Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
– Antoine de Saint-Exupéry
Installing MIT-Scheme via Package Manager
MacOS:
brew install mit-scheme
Ubuntu:
sudo apt-get update
sudo apt-get install mit-scheme
Basic REPL Usage
(REPL: Read-Evaluate-Print Loop)
-
Start the REPL with a single command
mit-scheme
. -
Load Scheme code into the REPL:
(The .scm extension can be omitted.)
-
View the manual:
-
Use the
man mit-scheme
command in the terminal to view the brief mit-scheme CLI manual. -
When in REPL, press Ctrl-C and then type H to see the interrupt manual:
-
Ctrl-C: Waits for the next keyboard input to decide the interrupt behavior.
-
Ctrl-G: Returns to the top-level REPL.
-
Ctrl-Z: Suspends the current mit-scheme process.
-
-
Press Ctrl-C and then type ? to see the manual for the next key input (option) and how it corresponds to REPL behavior (clear screen, suspend, exit, ignore interrupts, etc.).
-
-
If the REPL doesn’t respond:
-
Check if parentheses are properly matched; ( ( ) ( ( ) )
-
After interrupting with Ctrl-C, the prompt (
1 ] => / 2 error>
) may not reappear, which results in the “frozen” REPL. -
Worried about deep recursion? If the recursion depth exceeds the limit, the REPL will show Recursion depth limit exceeded. Aborting!. (According to mit-scheme manual, which you can get by
man mit-scheme
, stack size can be specified with CLI parameters, meaning MIT-Scheme has limited stack resources.)
-
-
ScHeMeScheme is case-insensitive.So
(LoAd "path/to/file.scm")
/(DEFINE x 1)
/(define x 1)
/(defiNE x 1)
, etc. won’t cause errors. -
History variable (procedure): Reuse procedures returned after evaluating expressions in the REPL:
1 ]=> (average-dump square) ;Value: #[compound-procedure 12] ; Can be reused in subsequent expressions, similar to GDB's history variable `$1` 1 ]=> (#[compound-procedure 12] 10) ; Not very convenient to use directly, but it works ;Value: 55 1 ]=> (define newfunc #[compound-procedure 12]) ; Can be bound to a new identifier for reuse ;Value: newfunc 1 ]=> (newfunc 10) ;Value: 55
Afterword
This Scheme REPL is quite basic. It doesn’t support history backtracking or cursor movement, however, since I don’t need it for anything too complex, it’s good enough for me.