mit-scheme REPL with command line history and tab completion
Asked Answered
T

2

27

I'm reading SICP and I'm using mit-scheme installed on my os x 10.8 laptop via homebrew.

Everything works as advertised, however I'm spoiled by the ease with which I get tab completion and command line history in REPL's for runtimes like Python and Node.js.

I'm not looking for anything heavy duty, but these features are pretty easy to come by in modern REPL's (it's just a simple startup file in Python and can be implemented in a few lines in Node.js).

Is there an easy way to get tab completion and command history in the mit-scheme REPL without a heavy-duty application or having to switch to emacs (i.e. in an xterm terminal)?

Timely answered 10/8, 2012 at 20:22 Comment(0)
J
64

Install the readline wrapper:

brew install rlwrap

Once installed, rlwrap scheme will give you persistent history, paren matching, and tab completion. I typically use rlwrap with the following arguments:

-r Put all words seen on in- and output on the completion list.

-c Complete filenames

-f Specify a list of words to use for tab completion. I'm using an abridged list of bindings from the MIT Scheme Reference Manual. Rather than republish the list here, you can find it in this gist. I have this file stored in "$HOME"/scheme_completion.txt

rlwrap -r -c -f "$HOME"/scheme_completion.txt scheme

1 ]=> (flo:a <tab tab>
flo:abs    flo:acos   flo:asin   flo:atan   flo:atan2  
1 ]=> (flo:abs -42.0)

;Value: 42.
Javelin answered 11/8, 2012 at 18:2 Comment(4)
Love this. This seems really useful for other programs too.Desegregate
Does something similar exist for Ubuntu?Charlottetown
For Ubuntu just sudo apt-get install rlwrap instead of brew install rlwrapMunster
In order to make rlwrap respect mit-schemes way of using CTRL+C and CTRL+G to interrupt calculations, use rlwrap with --polling and a few extra lines in .inputrc; cf. this SO questionLimekiln
C
2

I would actually recommend that you use Emacs, and use Geiser within that to access both the REPL and to help with scheme file editing. It also makes dealing with various Scheme REPLs such as Chez Scheme, Racket, MIT Scheme, Guile, Chicken, Gambit and Chibi Scheme effortless. Emacs remains very well tuned to use with Scheme and LISP. Highly recommended.

Curbstone answered 19/12, 2020 at 10:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.