mit-scheme Basic Usage

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)

  1. Start the REPL with a single command mit-scheme.

  2. Load Scheme code into the REPL:

    1 ] = > ( l o a d " p a t h / t o / f i l e . s c m " )

    (The .scm extension can be omitted.)

  3. View the manual:

    1. Use the man mit-scheme command in the terminal to view the brief mit-scheme CLI manual.

    2. 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.

    3. 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.).

  1. If the REPL doesn’t respond:

    1. Check if parentheses are properly matched; ( ( ) ( ( ) )

    2. After interrupting with Ctrl-C, the prompt (1 ] => / 2 error>) may not reappear, which results in the “frozen” REPL.

    3. 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.)

  2. ScHeMe Scheme is case-insensitive.

    So (LoAd "path/to/file.scm")/(DEFINE x 1)/(define x 1)/(defiNE x 1), etc. won’t cause errors.

  3. 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.

Wish You a Nice Day!
Built with Hugo
Theme Stack designed by Jimmy