CSCI 4150: Introduction to Artificial Intelligence, Fall 2005

Getting started with Scheme


Running MIT/GNU Scheme

You have two options for running MIT/GNU Scheme:

Installing MIT/GNU Scheme on your own computer

The first thing is to download the lastest stable version (7.7.1) of MIT/GNU Scheme. Installation instructions are also available from this web page. MIT/GNU Scheme is only officially available for x86 *NIX and Windows systems. I believe some students in previous years have gotten it running on a Mac, but I don't know any details.

If you have trouble installing MIT/GNU Scheme, one common cause is that your download was corrupted. Either try downloading it again, or check your download against the md5 checksums.

Note that the documentation (in HTML form) comes with the distribution. Find it and create a bookmark in your web browser.

Running MIT/GNU Scheme from CS machines

MIT/GNU Scheme is installed on all the machines in the freebsd.remote.cs.rpi.edu pool. You will need to use ssh (which you can do through SecureCRT) to connect to these machines.

You will need to use your CS account (which you will be getting if you don't already have one). You can remotely log in to the freebsd.remote pool from any computer on the internet.

You might find it most convenient to log in from a UNIX computer, because you can then X-host windows running on the remote machine. It is possible to do this through Windows, but you're on your own setting it up. You can also run emacs and scheme through a terminal (i.e., text) interface.


Using MIT/GNU Scheme

There are three ways you can use MIT/GNU Scheme. In order of my recommendation, they are:

  1. Run Scheme as an inferior process under gnu-emacs or xemacs. (This option is not available under Windows.)

  2. Run Scheme through Edwin, the emacs-like editor that comes with MIT Scheme. (Works in Windows too)

  3. Run Scheme standalone (and edit your code in some other editor).

I do not recommend running MIT/GNU Scheme standalone because there is no command line editing. Besides, I strongly recommend using emacs or Edwin to write your code, so you might as well run your code through them anyway.

If you're using Windows, you don't have the choice of using Scheme through gnu-emacs. However, you may want to download gnu-emacs anyway and use it to edit your code (because it is more user friendly than Edwin) and then using Edwin to run and debug. You can download emacs for Windows from http://ftp.gnu.org/gnu/windows/emacs/. (You have your choice of a "bare", regular, or "full" binary.) You may also be interested in the Emacs Windows FAQ.

If you're using UNIX of some sort, I suggest using gnu-emacs. Here's a comparison of the advantages and disadvantages of Edwin and gnu-emacs:

Edwingnu-emacs
+ scheme editing mode with electric parentheses + scheme editing mode electric parentheses
+ M-p and M-n scroll through command history - Can only yank previous command with C-c C-y
- Doesn't work with the X-cut buffer + X-cut buffer can be used to cut and paste between windows
- Missing some emacs features + It's real emacs!
+ Has nice debugging interface - Text debugging interface
- No pull down menus + Pull down menus

As a gnu-emacs "power user", I find Edwin kind of annoying because of missing gnu-emacs features, so I work using the gnu-emacs interface and only use edwin for some debugging sessions. (I usually use text debugging through gnu-emacs.) You may very well want the (relative) user-friendliness of emacs over Edwin, but if you know (or are willing to learn) emacs well enough that you don't need the pull down menus and such, then you may prefer Edwin.

Running Scheme under gnu-emacs

If you want to run Scheme as an inferior process in gnu-emacs or xemacs (again, this is not an option on Windows machines), then you'll need to:
  1. Download the xscheme.elc file. This is a byte-compiled elisp file that tells emacs how to run and interact with MIT Scheme. (Source file is xscheme.el in case you're interested.)

    This file should replace the xscheme.elc file that comes with emacs. You'll have to find the appropriate directory on your system. On my Mandrake Linux system, this is the directory: /usr/share/emacs/21.3/lisp. (This step is not necessary if you are running MIT/GNU Scheme from the CS department machines.)

  2. Add the following line to your ~/.emacs file

    (load-library "xscheme")

  3. Start (or restart) emacs, and it will load MIT Scheme's xscheme library.

To exit emacs, type C-x C-c (that's control-x followed by control-c).

Running Edwin

In Windows, you can start Edwin by simply using the shortcut from the Start menu, but in UNIX, you need to give the command:
scheme -edwin -edit
You will find it convenient to create an alias. For example, I have added the line:
alias edwin='scheme -edwin -edit'
to my ~/.bashrc file.

To exit Edwin, type C-x C-c (that's control-x followed by control-c).

Running Scheme standalone

You can run scheme all by itself, write your code in some editor (preferrably emacs), and then load your code via the command:
(load "filename.scm")
But again, I don't recommend this option.

To exit scheme, type "(exit)".


Using Emacs/Edwin with Scheme

Gnu-emacs and Edwin offer many special capabilities for working with Scheme code. However, there is a little bit of a learning curve for using emacs. This section suggests some resources for learning emacs and then describes the two types of buffers you will use in Edwin and emacs: a Scheme interaction buffer and a program file buffer.

Learn emacs

If you are new to emacs (or rusty), then you should go through the built-in tutorial. After starting emacs or Edwin, type C-h t (that's control-h followed by 't'). This tutorial will take you through the basics of editing, buffers, and saving/loading files.

Here are some other emacs resources you may find useful:

You may find better references for learning emacs on the web. (If so, let me know and I'll add links here.)

The Scheme interaction buffer

When you start Edwin, you automatically get a scheme interaction buffer called *scheme*. In gnu-emacs, giving the command M-x run-scheme will start Scheme in a scheme interaction buffer (also called *scheme*).

In the Scheme interaction buffer, you can type Scheme expressions and use one of the following commands to send them to the Scheme process to be evaluated:

Experiment with these commands until you understand how to send the expression you want to the Scheme interpreter.

If you make an error, you will get a beep and some error messages about calling RESTART. From here, you can get back to the top level of the Scheme interpreter by typing C-c C-c. You can also enter the (regular) debugger by typing (debug). In Edwin, it may offer to start the debugger for you.

In Edwin, M-p and M-n will take you through the previous commands sent to the scheme interpreter. In emacs, C-c C-y will yank the previous command.

Scheme program buffers

When you load a file with the extension .scm, Emacs/Edwin will enter Scheme mode. There are a number of commands to help you edit and run scheme code.

The M-z and C-x C-e commands work the same in this buffer as they do in a scheme interaction buffer. The result will be printed in the *scheme* buffer but also briefly displayed under the mode line of the emacs/Edwin window. These commands are useful for sending a single function to Scheme while you are developing a program.

The M-o command sends the entire buffer to the scheme interpreter.

Emacs/Edwin will indent you code for you! just press tab at the beginning of each line, and the cursor will move to the proper point to begin typing.

When typing comments, M-j will act like the return key except that it will start the next line with the comment character. In emacs,M-q will reflow a paragraph and properly comment it. (Edwin can do this too, but see below for how to set this nondefault keybinding in Edwin.)

For more information

There are a number of other emacs/Edwin commands that you will find useful. Refer to:

A few notes on using Edwin