
@a11ce has joined the channel

Does racket or drracket provide any CLI form of the automatic indentation to use as a linter? If not, where is the source for it so I can reimplement it on its own?

This is the method you are looking for: https://github.com/racket/gui/blob/81c7759987a99742d3138e96ca7b63a6b5d6920c/gui-lib/framework/private/racket.rkt#L819 Unfortunately, it’s tied to a text%
gui widget.

thank you! is there a formal definition of correct racket indentation so i can go off that instead of the source?


It’s a guide, not a formal definition though

The most annoying part of designing yours will probably be preserving comments :wink:

There’s also https://docs.racket-lang.org/reference/pretty-print.html?q=pretty-print#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29\|pretty-print but it won’t do all you want either

@amanrojjha01 has joined the channel

Can elisp be called from the command line? If so, one line of attack is to look at the racket-mode code.
https://github.com/greghendershott/racket-mode/blob/master/racket-indent.el

or this should be translated to racket!

Also - indenting is hard. It is worthwhile to look at write ups for indenters for other languages.
Great blog post: http://journal.stuffwithstuff.com/2015/09/08/the-hardest-program-ive-ever-written/

Also “A prettier printer” by Philip Wadler. https://homepages.inf.ed.ac.uk/wadler/papers/prettier/prettier.pdf

Also possibly useful as a library for a racket pretty-printer: https://docs.racket-lang.org/pprint/index.html

@soegaard2 Yes - you can call elisp from the command line with the --eval
option

It’s not so bad if you run it via emacsclient
as well, otherwise it can be a little slow.

@keith047 has joined the channel

I’m playing with gstreamer making an audio player. Gstreamer runs worker threads to handle playback and it communicates with the application sending messages over custom FIFO. The fifo has ffi functions to retrieve messages with time out. I’m not sure how best to integrate this into a Racket gui application so that these messages can be tied to callbacks.

What are people generally using as editors for racket? My guess is emacs & vim generally. I fired up DrRacket and had mixed feelings…it sure looked a lot like DrScheme from 20 years ago.

The overscan package might have some examples but sadly I was never able to get it working. https://github.com/mwunsch/overscan/tree/master\|https://github.com/mwunsch/overscan/tree/master

I saw there’s an LSP implementation, which intends to leverage DrRacket’s API, which seems like a good choice.

But considering the module system, I find it strange that DrRacket doesn’t seem to have more support around projects/workspaces/multiple files/whatever. If I’m just ignorant, let me know!

DrRacket and Emacs Racket Mode are the most popular and have the best Racket IDE functionality. That said racketeers use a wide variety of editors and IDE!’s; vim, VScode and others

I believe the Magic Racket plugin for VSCode uses the LSP.

Yep, I’ve been using that a little, and it’s not bad at all. I just spend so much time with vscode these days that it’s convenient to stay there with my keybindings and such.


The philosophy is that to avoid configuration / project files - and instead put the information into racket files. This way the information can be used in different way - some information can be checked statically.
See the section on info files in the docs.
If you happen to have a “project” in a folder, you can use a plt-file to distribute it.

Shows my ignorance, didn’t know that drracket had plugins.

Probably there are plugins to solve some of my nits.

It looks like DrScheme but a lot has changed

@keith047 I think the number of VSCode users are growing. If you want a project, consider porting racket-mode to VSCode.

I have little doubt about that :slightly_smiling_face:

@soegaard2 could never grok elisp, even when I used emacs like 20+ years ago

It also has scripts which are almost as powerful as plugins - the Script menu in the toolbar, quickscript in the documentation
https://github.com/racket/racket/wiki/DrRacket\|https://github.com/racket/racket/wiki/DrRacket

Probably just bad memories



I’m generally in favor of LSP, I feel like if I wanted to work on something that I’d go that route. But that would mean hacking on DrRacket probably, and I probably don’t have the need for any of this.

(sadly, 99% of my open-source contributions are driven by the needs I have for work)

I’m pretty sure you don’t need code Elisp to use Racket Mode

I meant for the “port racket mode to vscode” part

Maybe I didn’t know what you were talking about and said something dumb

Sorry slack gets confusing and out-of-order

But I think I’d be pretty happy with drracket with a) vim keybindings (I feel crippled without them) b) the file explorer thing c) readline-like behavior in the REPL. I’d be sorta surprised if all those things didn’t already exist.

Yeah I know but I kinda despise the thread thing.

If you want to use vim: https://docs.racket-lang.org/guide/Vim.html\|https://docs.racket-lang.org/guide/Vim.html

That’s the funny part - I usually only use vim for quick edits and commit messages. But my fingers are stuck.

(I can’t help with vim questions as I use DrRacket exclusively )

I wasn’t thinking of a direct port, so it’s not necessary to be fluent in Elisp to get a gist of what happens. It’s easy to underestimate both the DrRacket and racket-mode repls. There is a lot going on under the hood. It’s not just send text back and forth from the editor to a running racket process.

Let me know how you go about this! I had a similar problem a while back (without the GUI), and figured it would be easier to just write an interpreter in the C code which understood the “events”.

Has anyone tried any of the lsp implementations for Racket with an editor like VScode or similar?

Maybe that’s close enough.

@keith047 Have you tried booting up Emacs with a vim emulator?

:slightly_smiling_face:

Evil mode is really good

It is; I do wish it was more maintainable though (maybe Emacs in general) I tried making a bugfix a whie back and couldn’t work out how on earth I caused a segfault.

@soegaard2 I’ve used that magic racket extension in vscode. Are there other implementations of LSP for racket? I didn’t think to look that far.

The evil maintainers are also very busy. I submitted a patch for almost 6 months now and they haven’t merged it yet.

The limitation of racket-langserver
seems to be what APIs are provided by drracket. I think much is possible via drracket, but I would guess that it would need to have additional stuff exposed via API.

@keith047 Sorry - it seems a lot of happened with Magic Racket since I looked at it last. I thought it was a simple syntax highlighter, but there is much more to it than that.

I mean most of the things appear to exist in drracket - minus (AFAIK) good multifile support in drracket proper.

But there are weirdisms like how (again, tell me if I’m wrong) I can’t autocomplete with local definitions in the definitions/REPL in drracket, but this works in the cli REPL.

the magic racket repo asks for help mapping command- (or whatever per platform) so they use /
instead - and I end up putting λ
all over the place because that’s the default keybinding for “comment line” :stuck_out_tongue:

A DrRacket plugin DrComplete is very good for autocompletion.


DrRacket also supports autocompletion already, but only for definitions from other modules (not local definitions), IIRC.

Sweet. I’ll have to check out plugins in general. I confess though, I just had good memories of using Scheme in school long ago, and I wanted to try out racket to see how it felt to me now. I’ve been doing the AoC stuff as a good way to practice. But it doesn’t really feel like how I’d write real racket code.

There is also Fishy completion: autocompletion that is guaranteed to be in scope. https://github.com/sorawee/fishy-completion\|https://github.com/sorawee/fishy-completion. (Implemented as a script not a plugin)

Well, that’s a proof of concept. Use DrComplete instead. It’s far more mature.

@keith047 I do most of my work in Emacs with racket-mode
; however, I almost always have an instance of DrRacket running that I use for experimenting - basically as a fancy REPL.

Emacs still looks like Emacs from 20 years ago… or even earlier, really.

Yes, a timeless classic :)

@plragde you win.

Emacs reminds me of this 20 year old car …

There appears to be a way to bind an id in such a way that it contains compile-time information that can be extracted with syntax-local-value
and so that it can be treated as a normal runtime variable. How would I go about doing that? The procedure make-variable-like-transformer
seems relevant but not quite the right thing.

Thanks! I thought I had done my due diligence on prior work with gstreamer, and somehow missed this.

Like this?

#lang racket
(begin-for-syntax
(struct container (x)
#:property prop:set!-transformer
(λ (me stx) #'42)))
(define-syntax foo (container 'secret))
(begin-for-syntax (println (container-x (syntax-local-value #'foo))))
;; 'secret
(println foo)
;; 42
(set! foo 3)
;; 42
(println foo)
;; 42

DrRacket completion is based on imported documented identifiers, whereas the racket repl uses the namespace directly (which isn’t available for a file that you’re editing). The racket-mode completion support is much better, as is the drcomplete plugin.

The container part only exists at compile time, correct?

I think that’s correct but @sorawee should confirm.

What you described sounded to me like a use for syntax properties. Maybe you already know about those and/or that wouldn’t be suitable for what you have in mind. But I wanted to mention just in case.

Yes, it only exists at compile-time.

My instinct was to use syntax properties, but I can’t figure out how to attach syntax properties to a binding created by define
or let
. I can use free identifier tables to map ids to various compile time data structures but, although that’s how things are done in most compilers, I have a feeling that it’s not the best way to do things in Racket.

Syntax properties are for attaching compile-time information to terms, like the expression (+ 4 x)
. The approach with define-syntax
and syntax-local-value
is for attaching compile-time information to bindings.

A good rule of thumb: if you want to stick information on a name and have all places that name is used able to get that information, you want define-syntax
plus syntax-local-value
. If you want to stick different information on different use sites of a name, you want syntax properties.

Also, another way to attach an information to binding is to use a hash on identifiers.


Oh, I didn’t see @kellysmith12.21 already mentioned that.

define-syntax
+ syntax-local-value
is great when you have control over everything. But when you don’t have control over everything, the identifier table could work better.

Typed Racket uses identifier table, I think.

wrapper modules also work