One of my long-term goals is to work my way through How to Design Programs using Racket, and I recently started the Intro to Systematic Program Design on Coursera, which uses both HtDP and Racket. Naturally I thought to myself, with all the zeal of the newly converted: “Hey, instead of using the super easy/nice DrRacket GUI, let’s work through this course in Emacs using some sort of Racket mode! It’ll be easy!”
Dear future self/reader: this ended up being an 8+ hour detour into getting the damn thing to work. I hope this serves as some sort of cautionary tale about something or other.
I first installed Greg Hendershott’s racket-mode using
M-x package install RET racket-mode. I start a test.rkt file and all appears well. Until I tried to run that code through the REPL, accessed via
C-M-F5. That resulted in
Searching for program: no such file or directory, racket errors.
The crux of my problem was two-fold: first, Emacs does not automatically pick up shell/bash environment variables (paths) in OSX; second, I wasn’t able to find the
racket binary on my system after installing Racket 6.1.1. It took me way too long to figure that out. I ended up installing Racket 126.96.36.199 (a development version), which solved that problem. [Note: I don’t think it’s an issue with 6.1.1 – I think that the binary was accidentally deleted at some point.]
That got rid of the ‘racket not found’ problem, but a new error appeared when I tried to invoke the REPL:
unbound identifier in module error! What fresh hell is this? (There was another error prior to this one, but I was so frazzled and frustrated at that point I wasn’t logging
/Applications/Racket vX.Y.Z/bin/racket exists.
(The backwards slash after Racket escapes the space in the path.)
In Emacs, install
exec-path-from-shell. This will allow Emacs to read the system shell’s path. To
.emacs (or init.el), add:
(when (memq window-system '(mac ns))
Finally, make sure that you preface your
.rkt files with the header