The basics about using scheme ----------------------------- The versions of Scheme we will be using are DrScheme and MzScheme. DrScheme is nicer to use because it has a GUI interface with a built-in text editor and syntax checker. Use MzScheme if you are limited to a text-only interface (due to limited RAM if you are running Scheme on your personal computer or your dialup connection to the composers does not support X window programs). If you want to run Scheme directly on your personal computer, you can download the needed files from http://www.cs.rice.edu/CS/PLT/packages/drscheme/ Download DrScheme if you want the GUI version; it includes MzScheme as well. If you just want MzScheme, you can download that separately. There is another Scheme interpreter on the composers called scm, but I think MzScheme is better. To run DrScheme and MzScheme on the composers: --------------------------------------------- Follow the instructions on Web page http://www.udel.edu/topics/software/special/language/drscheme to include DrScheme and MzScheme in your path. (I don't recommend drscheme-jr because it takes longer to load, adds features I don't think are useful, and makes it more difficult to have an init file as explained below.) Execute the following line: cp ~chester/paradigms/dotmzschemerc ~/.mzschemerc From now on, MzScheme will load .mzschemerc automatically; this file provides a convenient way to edit files and load them into MzScheme. Type drscheme to invoke DrScheme, or mzscheme to invoke MzScheme. IGNORE THE FOLLOWING; IT DOESN'T WORK ANYMORE If DrScheme complains about not being able to open an X window, you must do the following commands: On a command line for your machine, type xhost strauss.udel.edu or whichever composer you are using. (On a PC, you may have to do something different; I am not familiar with their requirements.) On a command line for the composer, type setenv DISPLAY full_name_of_your_machine:0 For example, I use the command setenv DISPLAY jupiter.cis.udel.edu:0 for my workstation. (The four-integer id number for your machine might work in place of the full_name_of_your_machine, but I haven't tried it.) END IGNORANCE To run DrScheme and MzScheme on a personal computer: --------------------------------------------------- I recommend that you make a BAT file such as drsheme.bat: \Progra~1\PLT\DRSCHEME Put this file in a directory that is on your PATH. For MzScheme, make a BAT file such as mzscheme.bat: \Progra~1\PLT\MZSCHEME -f \classes\paradigms\mzscheme.ini Put this file in a directory that is on your PATH. Copy my file ~chester/paradigms/dotmzschemerc to your computer and call it mzscheme.ini; put it in the directory where mzscheme.bat expects to find it. Change the file as needed to invoke the editor you want to use. All the Scheme you need to know for Chapter 1 --------------------------------------------- (define ) Assigns the value of to the . (define ( ...) ) The value of is returned as the value of a procedure call of the form ( ...). Arithmetic operations: +,-,*,/. These can take two or more arguments. - can take one argument; (- n) evaluates to n with its sign changed. Arithmetic comparisons: <,<=,=,>=,>=. We will use these with two arguments, but they will take a variable number of arguments. Other arithmetic functions: (abs n) the absolute value of n. (remainer m n) the remainder of integer m divided by integer n. (even? n) (odd? n) test for even and odd, respectively. Conditional statements: (if ) (cond ( ) ( ) ... (else )) Boolean functions: and or, not. And and or take any number of arguments. Not takes one. Procedures that are described but not named: (lambda ( ...) ) Creation of local variables: (let ( ( ) ( ) ... ) ) Additional procedures of general use and for debugging: ----------------------------------------------------- IF a program seems to be running forever and it does not respond to one or two clicks on the Break button, press the Cntrl-K key combination to kill the program. Exit from DrScheme by mouse clicking an appropriate button (such as the X,-, file/Quit buttons). Exit from MzScheme by typing (exit). Do not use this command in DrScheme. (load ) Loads the file name by . The file name may include the path to the file if it is in another directory. ( ) This is defined by the init file I described above. Only available in MzScheme. (Not needed in DrScheme.) () Re-edits the last file you edited. (display ) Prints out the value of on the screen. (The procedures write and print do practically the same thing.) (newline) Terminates the current line on the screen; moves to next line. To record a transcript of an interactive session with Scheme on a composer, use the unix Script command and run your program in MzScheme. (trace ...) This command turns on the trace facility for the named procedures. When these procedures are called, a message showing the procedure call will appear. When the procedure call terminates, the returning value will be printed. Vertical lines will connect the procedure call message to the returned value message. (untrace ...) The trace facility is turned off for the named procedures. NOTE: Procedures trace and untrace are not normally part of Scheme. To make these procedures available, type the following command: (require-library "trace.ss") You can put this line in your init file for MzScheme if you wish. (In MzScheme, this command loads the compiled version of trace. DrScheme still can't handle compiled files yet, so it loads the source code, which takes longer to load and compile.)