Change the print style of the output from the Racket REPL

I am running problems from SICP using the #lang planet/neil in Racket. I would rather write my code in Emacs, and I use Geiser mode to run Racket REPL through Emacs.

As a result of the output of the racket results, many mcons are mcons , which makes reading the results difficult.

 racket@chap2.4.rkt > (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 "Select Language" dialog box. However, this requires the DrRacket GUI; is there any way to change this parameter for Racket REPL?

+5
source share
1 answer

Background: Unlike the SICP style scheme, the Racket list immutable. To get the modified lists, in Racket you use mlist . What #lang planet/neil/SICP does (I look), (require mpair) and then rename mlist to list . Therefore, when you write list in this #lang , you are actually using mlist .

Anyway, mlist print differently, by default. But you can change two parameters.

print-as-expression

 (print-as-expression #f) 

Now it will print as

 {1 2 3 4} 

Curly brackets instead of parentheses indicate that this is a mutable list. To configure this, set another parameter:

print-mpair-curly-braces

 (print-mpair-curly-braces #f) 

And now it should print as:

 (1 2 3 4) 

So that the regular Racket REPL always does this, I think you could put these two expressions in your Racket initialization file , for example. ~/.racketrc on OSX and Linux. Although I'm not sure if the REPL provided by Geiser reads the initialization file if you evaluate these expressions as soon as they should be saved for the Geiser REPL session, so you can put them in some .rkt file and visit it once.

+9
source

Source: https://habr.com/ru/post/1202282/


All Articles