Using Concrete Abstractions with Gambit

This web page provides information regarding the use of the Gambit implementation of Scheme with Concrete Abstractions: An Introduction to Computer Science Using Scheme, by Max Hailperin, Barbara Kaiser, and Karl Knight.

The information here currently corresponds with the Gambit-C version 3.0 of Gambit; we will try to track new versions of Gambit-C as they come out.

Obtaining Gambit

Gambit is an implementation of Scheme that is made freely available by Marc Feeley of the University of Montreal. It can be obtained from the web. Versions are available for Unix, PC, and Macintosh systems. The Macintosh version includes a development environment, while on the other platforms, you will need to use a separate text editor, such as emacs. (An emacs mode is provided that allows you to interact with Gambit from within emacs.) So far we have only tested Gambit with the software for our book under Linux, but we don't know of any reason why it wouldn't work equally well on other systems, with the exception of graphics. (Limited testing on a Macintosh supports this.)

Options for Gambit

The Gambit Scheme interpreter, gsi, has some settings that control how closely it conforms to the R4RS standard for Scheme, and hence how closely it corresponds to the expectations of the Concrete Abstractions textbook.

In particular, unless you specify otherwise, gsi will differ from our expectations in two key regards. First, it treats upper- and lower-case letters as always distinct. (I.e., it is "case sensitive.") Second, it doesn't allow names to end with a colon (i.e., the : character).

In order to turn off these two special behaviors, you can specify the -:s option when you run gsi. For more information on this, see the Gambit documentation.

There is another way you can turn off these two special behaviors, once gsi is running. You can evaluate

(set-case-conversion! #t)
(set-keywords-allowed! #f)
The advantage to this second method is that it can automated, by putting these two expressions into a gambc.scm initialization file, which Gambit will automatically load each time it starts up. (See the Gambit documentation for more on this.) The initialization file can also load libraries, as described below.

If you'd prefer, you can leave Gambit's normal behavior alone; you'll just need to be aware of this at a few places where the textbook assumes case insensitivity.

Libraries for use with Gambit

There are three areas of the textbook for which a special library needs to be loaded into Gambit. One is the graphical images, introduced in the application section of chapter 1 and also used in subsequent chapters. Another is the random procedure introduced in chapter 6, and also used in chapters 11 and 14. The final one is the object-oriented programming system, used in chapter 14.

Each of these libraries can be downloaded from the web below. Once you have one of the library files on your system, you can load it into Gambit using the load procedure. For example, you could evaluate (load "random") to load in the random library. If the random.scm file isn't in your current directory (folder) you might need to specify a pathname, such as (load "/usr/local/scheme-libraries/random") or (load "c:\\scheme\\libraries\\random"). You can also put the loads into a gambc.scm initialization file, which Gambit will automatically load each time it starts up. (See the Gambit documentation for more on this.)

This is the library for graphical images. It only will work on unix-like systems, and may need some minor modifications to accomodate local circumstances. In addition to the features described in the textbook (most succinctly in the appendix), there are a few extensions. Descriptions of those extensions and some notes regarding installation are in a separate web page.
This is the random procedure for use with chapters 6, 11, and 14.
This is the object-oriented programming system for use with chapter 14.

General notes

Names defined in both Concrete Abstractions and Gambit

There are a number of names that we define in Concrete Abstractions that are already pre-defined in Gambit. The only real problem this causes is that if you perform the definition from the book, you can't expect the name to simultaneously have both the new value and the one described in the Gambit documentation.

We list below the affected names, organized into categories and listed within each category in their order of their appearance within the book:

Positioning of (newline)

Starting in chapter 6, we use the newline procedure to break output into separate lines. Unfortunately, there are two different conventions in use by different Scheme systems. One is to always use newline at the start of each line of output, while the other is to always use it at the end of each line. As a result of this lack of standardization, wherever we positioned the uses of (newline) in our programs would result in output that looked odd on some systems. We've tried in the textbook to make choices that don't look too horrible on any system, with the result that the output tends to look sub-optimal on every system. In particular, there tends to be extra blank lines. If you are working consistently within Gambit (or any other one system), feel free to remove or reposition (newline) as necessary to make the output look best.

Chapter by chapter notes

Chapter 1
The procedures for manipulating graphical images need to be loaded from a library, as described above. Additionally, it is worth noting that the various basic blocks, such as rcross-bb, are neither pre-defined nor defined within the library. Instead, their definitions are in a separate file.
Chapter 6
In order to get the random procedure introduced in the chapter, you will need to load a library file into Gambit as described above. Also, there is one review problem at the end of this chapter that asks you to define a procedure with the name time. This will not be possible under Gambit, since Gambit reserves that name for a special form for timing the evaluation of expressions. Use another name instead.
Chapter 9
For the application section, we have a Gambit-specific version of the show procedure. As with the graphics library for chapters 1 through 4, we have only made this work on unix-like systems. This version of show simply uses the book's image->eps procedure to write the image out in Encapsulated PostScript format, then invokes the publically available ghostview program to view the file, and finally deletes it.
Chapter 11
Although you could use the SLIM simulator from the application section to work through the earlier sections of this chapter under Gambit, you'd be better off using SLIME. For the review problems, you will need to load random in as described above.
Chapter 14
You will need to load a library file into Gambit to get the object-oriented programming system, as described above. For the application section, you will also need to load random in as described above.
Chapter 15
Gambit cannot be used for this chapter, since this chapter doesn't use the Scheme programming language. You will need to use a Java 1.1 system instead.

For more information, see the parent web page, or contact Max Hailperin:
Mathematics and Computer Science Department
Gustavus Adolphus College
800 W. College Avenue
St. Peter, MN 56082