I'm doing problems from SICP, using the #lang planet/neil
directive in Racket. I'd prefer to write my code in Emacs, and I'm using Geiser-mode to run a Racket REPL through Emacs.
The way racket prints results tends to use a lot of mcons
which makes the results hard to read.
[email protected]> (list 1 2 3 4)
(mcons 1 (mcons 2 (mcons 3 (mcons 4 '()))))
According to this other question, the output style can be changed inside DrRacket by selecting the "write" output style in the Choose Language dialog box. However this requires the DrRacket GUI; is there a way to change this setting for the Racket REPL?
Background: Unlike SICP style Scheme, Racket list
s are immutable. To get mutable lists, in Racket you use mlist
. What #lang planet/neil/SICP
does (I'm guesing) is (require mpair)
and then rename mlist
to list
. So when you write list
in that #lang
, you're actually using mlist
.
Anyway, mlist
s print differently, by default. But you can change two parameters.
(print-as-expression #f)
Now it will print as
{1 2 3 4}
The curly braces instead of parentheses indicate that it's a mutable list. To tweak that, set another parameter:
(print-mpair-curly-braces #f)
And now it should print as:
(1 2 3 4)
To have the plain Racket REPL always do this, I think you could put these two expressions in your Racket init file, e.g. ~/.racketrc
on OSX and Linux. Although I'm not sure if the REPL provided by Geiser read the init file, if you eval those expressions once they should persist for a Geiser REPL session, so you could put them in some .rkt
file and visit it once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With