CprS376 Schedule
CprS376 Class 2

Scheme Programming in a Linux Environment

Class 1 - Chapter 1



Contents

Linux, Emacs, Netscape, Scheme

In order to enjoy programming with Scheme on a machine running the Linux operating sytem, you will first need to obtain an account on such a machine (see Prof. Parrish) and then you will need to become familiar with a few basic operations:


 
 
Exercise: Use Petite Chez Scheme To Run Several Scheme Programs

To invoke the scheme interpreter, type petite at the prompt in a command window. You should see a welcome message and the scheme prompt, a ">". At the scheme prompt, type "Hello, World!" followed by a carraige return. The interpreter will answer you back with an echoed "Hello, World!" showing that a string evaluates to itself. To hear more than just an echo, type (car '(scheme beam team)) followed by a carraige return. You will see that the "car" of the list (scheme beam team) is the first element of the list, the symbol scheme. For yet another example, type (cdr '(scheme beam team)) followed by a carraige return. You will see that the "cdr" (pronounced "could-er") of the list (scheme beam team) is the list obtained by removing the original list's first element, (beam team). Now type (exit) followed by a carraige return to exit scheme. Congratulations! You're now a scheme programmer!

$ petite
Petite Chez Scheme Version 6.0a
Copyright (c) 1998 Cadence Research Systems

> "Hello, World!"
"Hello, World!"
> (car '(scheme beam team))
scheme
> (cdr '(scheme beam team))
(beam team)
> (exit)
$

 
 
Exercise: Learn to Use Emacs for Your Scheme Programming

This involves two steps: First, you need to configure emacs to work with petite chez scheme, and then you need to work through a certain well-designed tutorial on unix, emacs, and scheme. To configure emacs, create a new directory in your home directory named "emacs" and cd into it.

mkdir emacs
cd emacs

Now launch your Netscape web browser, visit Indiana University to retrieve the file iuscheme.el, and download it into the newly created emacs directory. Once again, visit Indiana University to retrieve the file .emacs and download it to your home directory (NOT the emacs directory). Finally, you need to make a small change to the recently installed .emacs file so that emacs will know that we intend to do our scheme programming with Petite Chez Scheme. Return to your home directory and open emacs on the .emacs file.

cd
emacs .emacs &

Just below the first line of the .emacs file, which reads ";;; .emacs Scheme support", insert the following new line:

(setq scheme-program-name "petite")

Save the modified .emacs file and quit emacs. You are now ready to use emacs to compose and run your scheme programs. To learn how to do so, carefully work through this unix, emacs, and scheme tutorial from the Computer Science Department at Indiana University.


 
 
Exercise: Download the SICP Source Code

Login to your account on one of the WL119 machines, create a directory named "scheme" and cd into it.

mkdir scheme
cd scheme

Open the Netscape web browser and go to the MIT Press web page for our textbook. Find the link for Code from the book about half way down the page, and click on it. Find the listing for the file "allcode.zip" near the bottom of the page and download that file into your newly created scheme directory. Expand this archive with the command

unzip allcode.zip

Verify that you now have a great deal of scheme source code in your scheme directory. Open emacs on the file "ch1.scm":

emacs ch1.scm &

Use emacs to erase nearly all of the code in this file except the few lines of comments at the top, and the code belonging to section 1.1.4, dealing with the procedures square and sum-of-squares. Now insert a new line near the top of that file which makes the (perhaps rather extravagant) claim "I can deal with linux and emacs!" and save the modified file. As proof of your new capabilities, send me a copy of that file as though you were handing in homework. Make sure your initials are to be found somewhere in the filename. Log onto the machine calypso.sewanee.edu. Use ftp to transfer your file to your own account on calypso, and use cp to copy it into a directory on calypso especially prepared for this purpose, named /home/parrish/handin. From your own directory on calypso, you would execute a command such as the following:

cp ch1_spk.scm  /home/parrish/handin

 
 
Optional Exercise: Configure Your bash Shell for Programming with MIT Scheme

The SICP course materials assume that we will be programming with MIT scheme -- but we aren't. If you would like to experiment with this slightly non-standard scheme dialect, go to your home directory, make a backup copy of your file ".bash_profile", and then open emacs on the file ".bash_profile"

cd
cp .bash_profile .bash_profile_bak
emacs .bash_profile &

Insert the following two lines into the file ".bash_profile", save the modified file, and exit emacs.

MITSCHEME_6001_DIRECTORY=/home/guests/mitscheme
export MITSCHEME_6001_DIRECTORY

You are now ready to experiment with MIT scheme. If you wish to do so, the following notes may help you get started.

To use MIT scheme, type

alias mit-scheme="scheme -large -band 6001.com -edit

and hit enter. Now type

alias

to see a list of your aliases. Type

mit-scheme

or the longer line given above, to enter mit scheme and invoke the Edwin editor. Type C-h for (limited) help. Type (car '(1 2 3)) and hit C-x C-e to evaluate it. Type M-x logout to finish a session. Here, "C" means the command key (labeled ctrl on our keyboards) and "M" means the meta key (= Alt). A good deal of help directly targeted at the SICP course and MIT scheme is available from MIT. Try reading their Don't Panic notes and the MIT Scheme User's Manual (which is more user friendly than the MIT Scheme Reference Manual). Be sure to visit the MIT 6.001 SICP home page.