In the previous lab, you typed commands directly into the Scheme environment, which immediately evaluated and printed the result. While this use of Scheme is quite straightforward, it has at least two disadvantages. First, all program definitions must be retyped every time a program is to be run, as nothing is saved from one use of Scheme to the next. Second, the results of a computation are not saved, and thus they are difficult to print. This lab addresses both of these issues.
Next, give XEmacs the name of the file that you want to create or revise. Click on the dogeared-paper icon at the left end of the toolbar near the top of the XEmacs window -- the one with the word Open underneath it. A dialogue box pops up, with the names of various editable files displayed above and a prompt at the bottom that looks like this:
Find file: ~/Move the mouse pointer into the dialogue box and type in the name of the file you want to create. Conventionally, Scheme programs are stored in files with names ending in .ss. For example, you might call the first Scheme file that you create first-test.ss. Type this name in at the Find file prompt, after the slash, and hit the Enter key. (Do NOT click on the OK button.)
Often, it is convenient to move the XEmacs window to the right of the computer screen. This is accomplished by moving the mouse to the labelled bar emacs:... at the top of the XEmacs window. Press the left mouse button on this labelled bar, and move the mouse (keeping the left button depressed). The XEmacs window will follow your mouse movements. When the XEmacs window is where you want it, release the left mouse button. Similarly, you may want to move the dtterm window to the left of the screen, so you can see much of both windows at the same time.
While XEmacs is an extremely powerful editor, many common capabilities are highlighted with buttons and menus at the top of window. These menus are analogous to most word processing packages, and thus are not discussed here. Ask the instructor as questions arise. (If something particularly strange seems to be happening, type <Ctrl/g> to stop the processing of a command.)
Type the following Scheme definitions into the XEmacs file.
(define pi 3.141596535)
(define q 'quarts)
(define a (sqrt 2))
As you are typing, note that when you type a right parenthesis,
XEmacs shows you which left parenthesis it matches. This will be
particularly helpful when typing longer Scheme programs. Save the file by clicking on the save button at the top of the XEmacs window -- the one that shows a diskette icon. File first-test.ss now is ready for use within Scheme.
Return the mouse to the dtterm window and type scheme to begin running the Scheme environment. Within Scheme, you can use the definitions from a file with the load procedure. Here, you should type
(load "first-test.ss")
More generally, load allows you to specify any file by placing the
file name in double quotes.Check that the definitions from the file work as expected by typing
pi
q
a
Modify first-test.ss so that it contains a typographical error. (Remember to save the file again.) What happens when you try to load this version of the file into scheme?
(+ 2 3)
in the file and load it into scheme. Describe what happens.
(define r (+ 2 3))
(define s '(+ 2 3))
(define t (quote (+ 2 3)))
(define u ''(+ 2 3))
(define v (quote (quote (+ 2 3))))
(define w (+ 1/2 1/3))
Load the revised file into Scheme and check the definitions for each of the
variables r, s, t, u, v, w.
Explain the results that you observe.
This document is available on the World Wide Web as
http://www.math.grin.edu/~walker/courses/151.fa98/lab-editing.html