Setting up Emacs for SICP from Scratch

Joshua F Mathews
3 min readSep 12, 2020

--

I discovered Structure and Interpretation of Computer Programs, and it’s a ton of fun. So I figured I’d share how to set up Emacs to work with it. This article assumes no prior Emacs knowledge. End result: Emacs + MIT-Scheme + Geiser.

Photo from Wikimedia Commons

First, install MIT-Scheme, the Lisp dialect used throughout the book: brew install mit-scheme or sudo apt install mit-scheme .

If you’re on a Mac, I recommend downloading Emacs directly from the interwebs. Else, just use your package manager (notice the uncaught exception for Windows users).

The two most important keys in Emacs are control and alt, referred to as C and M respectively. Fire up Emacs, then press C-x-C-f , then type ~/.emacs.d/init.el

We’ll need to add the Melpa package repository to Emacs. Paste the following into your init.el:

Type C-x-C-s to save, then type M-x (alt-x). This will open up the minibuffer to allow you to enter in commands. Restart Emacs, (for fun, type C-x-C-c instead of the exit button).

Pop quiz: open ~/.emacs.d/init.el back up using the correct shortcut. Then you can start installing packages like crazy:

M-x package-install return geiser

Geiser will enable you do “REPL-Driven-Development,” giving you an instant feedback loop when making changes to your code. Add the following at the bottom of your emacs configuration and you’ll be ready to embark on a grand adventure.

Save and run M-x eval-buffer to load the new configuration into emacs, then open up a *.scm file. After that, type M-x run-geiser . This will launch a Scheme REPL (read-eval-print loop) in a new Emacs window, which is attached to the scheme file you are working on. You’ll learn a ton about the REPL in SICP.

If you type “Hello World” in the file window, then run C-M-x , you will evaluate the current line you’re on:

Geiser evaluating “Hello world”, marked below the REPL with an arrow.

Next, replace it with the function:

Then, enter C-c-M-e . This will evaluate the function fib, then move your cursor to the REPL. If you run (fib 10), it’ll evaluate to 89.

And there you have it! A simple Emacs setup for SICP. Here’s the full init.el

And here’s a Geiser cheatsheet with all of the commands listed:
https://www.nongnu.org/geiser/geiser_5.html

--

--