scheme  

Mar 29, 2015 • Michael Chen

Structure and Interpretation of of Computer Program (SICP) is a classic textbook in computer science. It was formerly used in the introductory programming class of Massachusetts Institute of Technology (MIT) and other schools. Scheme, one of the main dialect of Lisp, was chosen as the language in this book. If you want to “enjoy” this classy book, just a few simple steps are needed.

Install Scheme on OS X

There are several implementations of Scheme available on OS X; some can be installed via Homebrew. I recommend Homebrew when possible. You may choose one among MIT/GNU-Scheme, Guile, Gambit, or other implementations. For the intro of Homebrew, see my previous post

To install MIT/GNU-Scheme on OS X:

$ brew install mit-scheme

Edwin is a Emacs-like editor built with MIT/GNU-Scheme. If you are familiar with Emacs, Edwin is almost the same thing. To start Edwin:

$ scheme --edit

Another way to start Edwin is using the command (edit) or (edwin) from within the Scheme interpreter.

However, on OS X, Edwin is initialized from XQuartz. The interface is not as beatiful as that of Emacs from iTerm or that of Aquamacs, and the font size is too small. Besides, Emacs has Scheme mode as well. Therefore, using Edwin instead of Emacs doesn’t gain many benefits.

Use Emacs for MIT/GNU-Scheme

DON’T install geiser if you want to use MIT/GNU-Scheme as Scheme interpreter. geiser will change the behavior of some hot key by calling guile or racket.

First, load xscheme package when you start Emacs. Set it in your ~/.emacs:

(require 'xscheme)

When editing Scheme files, you can start MIT/GNU-Scheme interpreter subprecess by invoking M-x run-scheme. After calling Scheme interpreter, you can evaluate the expression to the left of point by C-x C-e, the current region by C-M-z, and the current buffer by M-o.

Use Emacs for Guile

Install geiser if you want to use Guile. To install geiser in Emacs, invoke M-x package-install RET geiser.

When editing Scheme file, you can start Guile interpreter by invoking M-x run-geiser. After calling Scheme interpreter, you can evaluate the expression to the left of point by C-x C-e, the current region by C-M-z, and the current buffer by M-o.

Use Emacs for other Scheme implementations

If you want to use CHICKEN Scheme or Racket, use geiser. Follow the section Use Emacs for Guile.

If you want to use other Scheme interpreter, e.g. Gambit Scheme, use xscheme package. You may need to modify scheme-program-name variable to use specific Scheme interpreter. For example, to use Gambit Scheme:

(setq scheme-program-name "gsi -:d-")

Then, start Gambit Scheme interpreter by invoking M-x run-scheme.

Use DrRacket (formerly DrScheme)

DrRacket is a full IDE for Racket, usually used among computer science courses that teach Scheme or Racket. On OS X, DrRacket uses a mix of Emacs and OS X style hot keys. If you prefer IDE, you may try DrRacket.