|Computer Science Fundamentals
Emacs may be customized to simplify Scheme programming in two ways:
Start Emacs and open the file .emacs in your home directory.
Position the editing cursor at the bottom of the file by moving the mouse pointer to the end of the file and clicking with the left mouse button.
The customizations that you need to add are stored in the file /home/walker/153/emacs-customization. To copy this file into .emacs, bring up the File menu from the menu bar and select the Insert File... operation. Erase the ~/ characters that are supplied automatically and type in the full name of the customization file. Press <Return> at the end of the file name. The contents of the file will appear in the Emacs window.
Save the .emacs file and exit from Emacs.
Check whether the customization succeeded: Restart Emacs and open a new file named sample.ss in the Emacs window. Look at the "mode line" at the bottom of the Emacs window; it tells you what file you're currently editing and which of Emacs's numerous editing modes are active. If you see the word Scheme somewhere on that line, you did step 1 correctly.
Experiment with formatting of Scheme within Emacs:
Type in the following Scheme definition:
(define h5 (+ 1/1 1/2 1/3 1/4 1/5))
Place the editing cursor anywhere on the second line of the definition and press the <Tab> key. Notice that Emacs indents the line. The number of spaces that Emacs inserts is determined by a set of conventions that have been found to result in highly readable programs.
Run Scheme within Emacs:
The customization that you performed in step 1 enables you to run Chez Scheme inside the Emacs window rather than in the terminal window, if you wish. The choice between using a terminal window or Emacs as the environment in which to run Chez Scheme is a matter of personal preference and style; after today's lab, you may use whichever setup you find most comfortable.
To run Chez Scheme inside Emacs, press the <F1> key. Your Emacs window will split into two parts, and the Chez Scheme interactive interface will be started in one subwindow.
Move your cursor to the top (Scheme) window, and enter a Scheme expression, such as (+ 2 3). Press the <Enter> key to check that Scheme operates directly on what you have typed.
Move your cursor to the bottom (editing) window, placing it at the end of the definition that you typed in back in step 3a and press <Alt/Enter>; that is, hold down the <Alt> key and simultaneously press <Enter>. Notice that Chez Scheme issues a second prompt, right next to the first one; this indicates that the interactive interface has processed the definition and is now ready for another definition or command.
Move the editing cursor to the position immediately following this second
prompt in the top window, move the cursor to the beginning of the next
line, type h5, and press the keypad <Enter> key. Notice
that Chez Scheme responds by printing the value of the symbol
h5, proving that it did indeed see the definition in step 4c.
When Chez Scheme is running in an Emacs window, you can't shut it down with <Control/D>, since Emacs regards this as a delete-character command. Type (exit) instead. Although this has the syntax of a procedure call, Chez Scheme recognizes it as a shutdown directive.
Press <F1> again, so that Scheme is running in one window and you are editing a file in another.
Try exiting from Chez Scheme before closing the Emacs window in which it is running. Emacs will remind you by printing the question
Active processes exist; kill them and exit anyway? (yes or no)
at the bottom of the window. Type the word yes in response; Emacs will shut down Chez Scheme for you as it shuts itself down.
A Scheme comment begins with a semicolon and extends to the end of a line. Although one semicolon is enough to begin a comment, most Scheme programmers use several semicolons to indicate the scope or importance of a comment. A three-semicolon comment line is more likely to apply to the program as a whole, or to be extremely important; a similar line beginning with just one semicolon is likely to apply only to the line that immediately precedes or follows it and to be an off-hand remark.
Add a comment to your Scheme program file from the previous lab, including
the above information. Save the file and use the
procedure to load it into the Scheme interactive interpreter again.
|Example that returns True (#t)
|Is argument a number?
|Is argument a symbol?
|Is argument a boolean value?
|Is argument a procedure?
|(eq? 'a 'a)
|Do arguments represent identical symbols?
|(eqv? 'a 'a)
|Similar to eq?
|(equal? (+ 1 1) (sqrt 4))
|Are arguments the same symbols, numbers, booleans, or lists?
To gain experience with these predicates, try the following steps:
This document is available on the World Wide Web as
created June 6, 1996 by John David Stone
last revised January 24, 2005 by Henry M. Walker
|For more information, please contact Henry M. Walker at email@example.com.