Scheme at IU

This document provides information about use of the Scheme programming language in the Indiana University Department of Computer Science.

At IU prospective undergraduate CS majors use Scheme in their first course, C211, and in the required programming languages core course, C311 and the optional compilers course, P423. The initial graduate-level programming languages course, B521 also uses Scheme, as does the graduate level programming language implementation course, P523. Scheme is also used as a tool by students in several other courses, such as the AI course, B551.

Scheme is much used in programming languages research at IU, and is the focus of the IU educational infrastructure project.

There is a local newsgroup cs.scheme, as well as the global comp.lang.scheme.

For Scheme code to be legible, it is important to follow good indentation rules.

The Scheme Repository, maintained locally, has lots of additional information on Scheme.


Using Scheme

Chez Scheme may be run in a shell on any general-use IUCS Unix machine with the command scheme.

Most people, however, prefer to run Scheme as a subprocess of the emacs editor, which also provides support for editing Scheme programs. The following steps customize emacs so that it provides good support for Scheme.

  1. Create a directory called emacs in your home directory.
  2. Copy the file /l/www/proglang/scheme/iuscheme.el to your emacs directory.
  3. Copy the file /l/www/proglang/scheme/.emacs to your home directory. If you already have a .emacs file, add the contents of this file to it. If you already have some Scheme support in your .emacs file, you might want to delete it. Usually this setup is all you need to live comfortably with Scheme.

Now, the next time you edit a .ss (Scheme source) file, or when you type Esc-x run-scheme to start a Scheme session, things will work out nicely. In particular, when you press return, the next line will automatically be indented according to our indentation rules. Also, the new scheme-mode command Ctrl-c Ctrl-i automatically re-indents the current definition. Use this often when you edit code to re-indent code that has been moved and expose mis-matched parenthesis errors. Even if you do not think you have made any changes that effect indentation, run this command. If lines change indentation unexpectedly, or the indentation does not look right, check your parenthesis.

The tutorial designed for the C211 course provides an introduction to emacs, Scheme, among other aspects of the local environment, that others may find helpful as well.


Advanced emacs support information

The above instructions are sufficient to get you started writing Scheme programs in emacs with all sorts of support. If you want to know what you've just done and why you've done it, read on...

The file iuscheme.el serves two basic functions. The first is probably the most important, but needs a history lesson. The original emacs program started at MIT, where Scheme originated and is still much used. So they wrote two handy emacs-lisp files called xscheme.el and scheme.el, and got these files placed on the general distribution of emacs (that is, every emacs in the world has these files). Unfortunately for the rest of the universe, they wrote their Scheme mode specifically for the MIT Scheme, causing (for Chez Scheme users, at least) the infamous Error in open-input-file: error opening "-emacs": No such file or directory.

The folks at Carnegie Mellon, for reasons of their own, wrote a cleaner package of emacs Scheme support, cmuscheme.el, and after a bit they also got their file into emacs distributions. Unfortunately, emacs distributions differ as to which emacs setup is the default. One way to make sure you get the more friendly CMU version is to add the following lines to your .emacs file:

(autoload 'scheme-mode "cmuscheme" 
  "Major mode for Scheme." t)
(autoload 'run-scheme "cmuscheme" 
  "Switch to interactive Scheme buffer." t)
(autoload 'run-alt-scheme "cmuscheme" 
  "Switch to interactive alternative Scheme buffer." t)
At least if you're at IU, you will probably prefer to use iuscheme.el, which extends cmuscheme.el as follows:

Other Extensions

The file /l/www/proglang/scheme/iuindent.el may be loaded along with iuscheme.el to provide a different style of indentation that many prefer, especially in the C311 course.

If you run emacs in a display mode that supports multiple fonts (such as X-windows, but not dumb-terminal emulation), you may enjoy your Scheme programs being "fontified" using /l/www/proglang/scheme/schemefont.el. To use it, just stick the contents of this file in your .emacs file, or put it in your emacs directory and add

(load-library "schemefont")
somewhere after the load-path extension in your .emacs file.

If you sometimes prefer to use matching brackets in place of parenthesis (which Chez Scheme allows), place the file /l/www/proglang/scheme/balance-mode.el in your emacs directory, and add the statement

(require 'balance-mode)
to your .emacs file. The command Esc-x balance-mode toggles a minor mode for automatic parenthesis and bracket balancing: if you type ')', but it matches '[', then ']' will be inserted instead. If you want this behavior in all Scheme editing sessions, also add the expression
(add-hook 'scheme-mode-hook (function (lambda () (balance-mode t))))
to your .emacs file.


-- Chris Haynes and Eric Hilsdale.