aaron maxwell

Using Gnu Emacs With SCMUtils

If you are interested in both physics and computer science, there is a real treasure of a book you owe it to yourself to check out. It's called Structure and Interpretation of Classical Mechanics. The full text is online at that link, and you can also buy a physical copy. I won't describe it further in this post; good summaries can be found in the reviews on Amazon.

Accompanying the text is an open-source numerical and symbolic math library called "scmutils", meant to be run in MIT's version of Scheme. (download and install instructions) MIT Scheme includes an Emacs-like editor and execution environment called "Edwin", which acts as an interface to the whole system.

Edwin has some nice features, including a user-friendly debugger and symbol completion. Most of the time, however, I prefer to use full-fledged Gnu Emacs as the interface. Setting this up is actually pretty simple, once you have downloaded and installed scmutils. Just include the following in your .emacs file:

(defun mechanics ()
    "ROOT/mit-scheme/bin/scheme --library ROOT/mit-scheme/lib"

Replace ROOT with the directory in which you installed the scmutils software. (Remember to replace it in both places. If it is installed differently on your system, just make sure the string has the form "/path/to/mit-scheme --library /path/to/scmutils-library".) Restart emacs (or use C-x C-e to evaluate the mechanics defun), and launch the environment with the command M-x mechanics.

There are a few nice Emacs and scheme-mode features you can use. A handy way to work in the environment is with two buffers open at once. One buffer will be in the mechanics enviroment (i.e. scheme interpreter) launched with the mechanics command; we'll refer to this as the "mechanics" buffer. The other buffer will be open to a file containing Scheme/Scmutils code. The idea is that you write your code in the file, save it, then tell the scheme process to load the file. You do this by switching to the mechanics buffer, then typing C-c C-l. (That's "L", not "one"). You will be asked for, and must specify, the file to load the first time. It is remembered on subsequent invokations, so after making a change to the file and saving, you can just switch to the mechanics buffer and type C-c C-l [ENTER] to reload. It's very simple and fast.

In the mechanics buffer - which happens to be in the normal Emacs scheme interaction mode - a command history is kept. You can cycle up and down through the command history with C-up and C-down. If you make a mistake and get to the error prompt, or start a calculation that is taking too long, you can abort and return to the normal prompt by typing C-c C-c. Other useful commands can be found from M-x describe-mode .