HOW TO RUN SCHEME by Gary T. Leavens Department of Computer Science, Iowa State University File $Date: 1997/01/23 03:13:51 $ This document gives basic ways to use Scheme on the Com S department machines and on Project Vincent, and ways to use Scheme from within emacs. It also describes how to get Scheme for other computers. 1. STARTING SCHEME ON HP-UX The default for this course is to run the SCM interpreter for Scheme on the Com S department HP-UX servers. MIT Scheme is another interpreter that is also available on these machines. (The interpreters are found in /usr/unsup/bin, so you must have this directory in your shell PATH for the interpreters to work. But this is the default on the Com S department HP-UX servers, so you shouldn't have to do anything special to set this up.) 1.1 STARTING SCM Log in to your Com S account. Then type (at the shell's prompt, %) scm and then hit the ``return'' (or enter) key. Be sure your input is in lower case (NOT CAPITALIZED). You will see something like the following. SCM version 4e1, Copyright (C) 1990, 1991, 1992, 1993, 1994 Aubrey Jaffer. SCM comes with ABSOLUTELY NO WARRANTY; for details type `(terms)'. This is free software, and you are welcome to redistribute it under certain conditions; type `(terms)' for details. ;loading "/usr/unsup/scheme/scm/Transcen.scm" ;done loading "/usr/unsup/scheme/scm/Transcen.scm" > with the prompt ``> '' indicating that SCM is waiting for your input. Now type your input, followed by a return. (Try typing (+ 2 3) and then ``return'' for starters.) 1.2 STARTING MIT SCHEME Log in to your Com S account. Then type (at the shell's prompt, %) scheme and then hit the ``return'' (or enter) key. You will see something like the following. Scheme saved on Thursday December 2, 1993 at 6:18:35 PM Release 7.3.0 (beta) Microcode 11.146 Runtime 14.166 1 ]=> with the prompt ``1 ]=> '' indicating that MIT Scheme is waiting for your input. Now type your input, followed by a return. 2. STARTING CHEZ SCHEME ON VINCENT Log in to your Vincent account. Then type (at the shell's prompt, %) add scheme and then hit the ``return'' (or enter) key. Be sure your input is in lower case (NOT CAPITALIZED). You will see something like the following. You have added Chez Scheme version 4.1 You can put the add scheme command in your .startup.tty file to have it automatically executed each time you log in. Now just type scheme and hit ``return''. You will see the following: Chez Scheme Version 4.1 Copyright (c) 1991 Cadence Research Systems > with the prompt ``> '' indicating that Chez Scheme is waiting for your input. Now type your input, followed by a ``return''. 3. WORKING WITH SCHEME 3.1 EXITING SCHEME To exit any of the scheme interpreters (SCM, MIT Scheme, or Chez Scheme) type (exit) or type a control-d (hold down the ``control'' key and at the same time type a ``d'', without the quotes.). In MIT Scheme, you will be prompted to see if you really want to exit. 3.2 MAKING A TRANSCRIPT To record your session with a Scheme interpreter in a file named ``trans.out'' (without the quotes), that is to put your inputs and its outputs in the file ``trans.out'', type the following to Scheme (transcript-on "trans.out") This must be typed exactly as above, with the double quotes ("). To make a transcript in some other file, write that name instead of trans.out. 3.3 LOADING FILES It is very convenient to put your code for Scheme programs in files, and have Scheme read those files. A standard way to have Scheme read a file is to use the load procedure. The advantage of this is that load can be called from a program; for example, you can have one file that loads several others. Another advantage is that you can use load after you have already started Scheme. An example of using load after starting Scheme is as follows. (Suppose that ``> '' is the Scheme prompt, you don't type that.) > (load "foo.scm") If your files have errors you will see an error message; for example, "foo.scm", line 3: ERROR: list: end of file in is an error message (from SCM) that means that foo.ss is missing one or more right parentheses (a common mistake). In SCM and Chez Scheme, you can also load files by simply listing the files you want to load on the command to start Scheme. For example, using scm to read in files named ``foo.scm'' and ``bar.scm,'' you would type at the operating system prompt: scm foo.scm bar.scm This allows you to load some files by default whenever you start SCM (or Chez Scheme). A standard way to do this is part of setting up your account for this course. (Should you need to make such a script for yourself, you could proceed as follows. Make a shell script, say ~/bin/scm610, containing the following line. exec scm file-I-always-load.scm $* The line says to start Scheme and load the file ``file-I-always-load.scm'' and then any other files you specify on the command line. Be sure that there is a newline following this line. That is, if emacs asks you if you want one, answer yes. Remember to change the Unix file mode (permissions) on the shell script file you just created to make it executable. Suppose you called the shell script scm610 (don't call it scm or scheme!), then you would execute the following: chmod +x ~/bin/scheme To check that this has been set up properly, try the following from the Unix shell. rehash which scm610 echo ~/bin/scm610 The responses to the last 2 commands should be the same. Note, this will not affect any scheme interpreters that you already have running.) 3.4 SCHEME ADVANCED TOPICS The ``Revised^4 Report on The Algorithmic Language Scheme'' is available on-line. You can find it from the URL http://www.cs.indiana.edu/scheme-repository/R4RS/r4rs_toc.html with your favorite WWW browser. Or you can read it locally by using the Unix program info or the info mode of emacs (M-x info). Select ``Unsupported'' from the first menu, then select ``r4rs''. There is an internet newsgroup for Scheme: comp.lang.scheme. You might also want to look into the WWW for the Scheme home page: http://www-swiss.ai.mit.edu/scheme-home.html and the Internet Scheme repository: http://www.cs.indiana.edu/scheme-repository/home.html See the Unix manual page for details about the particular Scheme interpreters. These will tell you how to do such things as compiling files and saving your session so you can start where you left off. For example, to see the manual page for SCM type the following to Unix. man scm To see the manual page for MIT Scheme on HP-UX, or Chez Scheme on Vincent type: man scheme (This will show one screenful; to see more type a space.) You can look around at the source directories for MIT Scheme and SCM for other interesting information. The source directory for SCM is /usr/unsup/scheme/scm See the file MANUAL in that directory for more information. SCM also comes with a library of scheme code, called SLIB. You can read about it using the info program or the info mode of emacs. The source directory for MIT Scheme is /usr/unsup/scheme/dist-7.3 You can read about MIT Scheme using the info program or the info mode of emacs. Select the topic ``Running MIT Scheme'' or 4. EDITING SCHEME FILES 4.1 EDITING SCHEME FILES WITH EMACS Of the standard Unix editors, emacs has the best support for Scheme programming (and for other programming languages also). In addition to matching parentheses (when you type ``)'' it shows which ``('' matches it) for you, emacs knows how to indent Scheme programs to make them look good. But before emacs will do this for you, it must know that you are editing a Scheme program. The best way to tell emacs that you are editing a Scheme program is to use the customizations found in the file. /home/course/cs342/public/docs/sample-.emacs Either copy that into your file ``~/.emacs'', or edit the relevant lines into your file ``~/.emacs''. With the relevant customization of your file ``~/.emacs'', when you are editing a file whose name ends in ``.scm'' (or ``.ss'') then that is a Scheme file. Be sure that all your Scheme file names end in ``.scm'' (or ``.ss'')! For example ``member.ss'' is a good name, but not ``junk''. To find out about scheme-mode in emacs, edit a scheme file and then type C-h m (that is, control-h and then ``m''). You will see a table of commands that looks like the following (which has been simplified; what you see in emacs by typing C-h m is the truth). What you type What it does ============= ============================= RET newline-and-indent LFD newline DEL backward-delete-char-untabify TAB scheme-indent-line C-c C-l scheme-load-file C-c C-z switch-to-scheme C-c C-c scheme-compile-definition-and-go C-c C-r scheme-send-region C-c C-e scheme-send-definition C-x C-e scheme-send-last-sexp ESC C-x scheme-send-definition ESC C-q scheme-indent-sexp C-c ESC r scheme-send-region-and-go C-c ESC e scheme-send-definition-and-go For example, if you type C-x C-e (control-x and then control-e), it sends the previous s-expression (a parentheses balanced thing you typed) to the Scheme process. 2.2 INTERACTING WITH SCHEME FROM EMACS To run Scheme from within Emacs, start emacs, and then use the command M-x run-scheme. (That is, type ESC, then ``x'' then at the prompt ``run-scheme''. This will put you in ``inferior scheme mode'' in a buffer called *scheme*. You will soon see the scheme system starting, just as if you had run it directly from the project vincent shell. (The name of the command run is given by the Emacs variable ``scheme-program-name''.) You can type expressions at the prompt, and then by typing ``return'', you will see them evaluated. To find out about inferior scheme mode in emacs, from the *scheme* buffer type C-h m. You will see a table of commands that includes those in the table above, and some additional ones. What you type What it does ============= ============================= DEL backward-delete-char-untabify TAB scheme-indent-line C-d comint-delchar-or-maybe-eof RET comint-send-input C-x C-e scheme-send-last-sexp C-c C-l scheme-load-file C-c RET comint-copy-old-input C-c C-\ comint-quit-subjob C-c C-z comint-stop-subjob C-c C-c comint-interrupt-subjob C-c C-u comint-kill-input ESC C-q scheme-indent-sexp ESC C-x scheme-send-definition ESC p comint-previous-input The basic addition is that when you type a return (RET), what you typed is sent to the Scheme interpreter. You can edit the input using emacs commands, but note that whatever is on a line at the time you type return (RET) is sent to Scheme, and is not affected by further editing. However you can go back up in the buffer and send an edited expression again by placing your cursor just to the right of the last right parentheses, and typing return. You do not need to separately exit Scheme and emacs, as exiting emacs will kill Scheme. (However, if you use MIT Scheme, it's best to exit Scheme first, otherwise it leaves a core dump.) The scheme running under emacs does not automatically know about changes you make to Scheme code files or other emacs Scheme buffers. You have to either explicitly load the file (use load-file in Scheme as described above), or use a scheme-send command (such as C-x C-e) in the buffer where you are editing your code. (Note that these have to be in the same emacs process, if you are on a workstation and you can move two emacs windows independently, they are not the same.) 2.3 EDITING SCHEME WITH VI If you don't already know how to use vi, don't bother to learn. The vi editor does not know how to format Scheme code. If you must use vi, invoke it with the ``-l'' option, which will make it match parentheses for you. There is also a ``vi-mode'' in emacs, which allows you to use vi's editing commands, but all the features of emacs. 3. OTHER SCHEMES The following information is included for completeness. You probably don't need it, unless you have a home computer. A more up-to-date version of this information can be obtained by reading the frequently-asked-questions (FAQs) posted to the newsgroup comp.lang.scheme. You can also get up-to-date information from the following URL. ftp://ftp.cs.indiana.edu/pub/scheme-repository/doc/misc/scheme_2.faq 3.1 SCHEME FOR A PC If you want a commercial PC version, you can buy, among others, EdScheme from Schemer's Inc. EdScheme runs on Macintosh, DOS and Atari ST and costs $50 for DOS ($60 for the Mac). It includes an incremental compiler, and editor, and is a close match to the IEEE standard. Implemented by Iain Ferguson, Edward Martin, and Burt Kaufman. The book (The Schemer's Guide) is 328 pages long costs $30. For more information about these products, write to Schemers Inc., 2136 NE 68th Street, Suite 401, Fort Lauderdale, FL 33308, call 305-776-7376, or fax 305-776-6174. You can also send email to 71020.1774@compuserve.com. They also have a windows version and a product (3DScheme) for three-dimensional modelling in Scheme. If you have an IBM PC or compatible you can get a free scheme interpreter for it. The free system is called PC Scheme. One way to get this is to buy the book ``PC Scheme'' (1988, Scientific Press). The advantage of doing that is that you get the documentation. (You may want this documentation even if you get the free version.) PC Scheme includes an optimizing compiler, an emacs-like editor, inspector, debugger, performance testing, foreign function interface, window system and an object-oriented subsystem. Conforms to the Revised^3 Report on Scheme. However, the version of PC Scheme in the book ``PC Scheme'' is that it does not work on '486-class PCs. To get a version that works, bring a 3.5-inch high density formatted floppy disk to the instructor, or, if you know use anonymous ftp to ftp it from cui.unige.ch in the directory PUBLIC/pcs /home/cs227/PCScheme. This version is PCS/Geneva, which is a cleaned-up version of PC Scheme developed at the University of Geneva. The main extensions to PC Scheme are 486 support, BGI graphics, LIM-EMS pagination support, line editing, and assmebly-level interfacing. (TI's PC Scheme gives users full Revised^3 support along with many primitives for DOS, Graphics and Text Windows. A powerful built-in optimizing compiler produces fast code.) The beta version of PCS/Geneva has been tested on XTs, ATs, AT386s and AT486s under various DOS and OS/2 versions. It even runs on Hewlett-Packard's HP95LX. 3.3 SCHEME FOR A MACINTOSH If you have an Apple Macintosh, you can get MacScheme from Lightship Software. MacScheme is a Scheme interpreter and compiler for the Apple Macintosh, and includes an editor, debugger and object system. MacScheme costs $125 (includes compiler) and Scheme Express costs $70 (interpreter only). It requires 1mb RAM. A development environment (MacScheme+Toolsmith) costs $495. MacScheme+Toolsmith includes support for menus, windows, and interfaces to the Macintosh Toolbox, and can create small standalone Macintosh executables. Write to: Lightship Software, PO Box 1636, Beaverton, OR 97075, or call (503) 292-8765. They're moving to California. The temporary phone number is 415-940-4008 (Liz Heller). The new phone number will be 415-694-7799. MacScheme is distributed by ACS, 2015 East 3300 South, Salt Lake City, UT 84109-2630, 1-800-531-3227 (801-484-3923). Other places to call are Academic Software at 800-531-3227, or Ted Essen of Computer Biz at 408-456-0100. There is a book "MacScheme" published by MIT Press which includes a manual and a disk (perhaps not for the interpreter, but merely some programs, I'm not sure), reportedly for $37.50. MacScheme+ToolSmith is documented in a book by the same name (Semantic Microsystems, 1987). There is a free Scheme interpreter for the Macintosh called Gambit 1.9, which is available by anonymous ftp from trex.iro.umontreal.ca. Gambit is an optimizing Scheme compiler/system. It conforms to the IEEE-Scheme standard (IEEE P1178) and the Revised^4 Report on Scheme (R4RS). The system supports the whole numeric tower (i.e. integer, rational, real and complex numbers). It also has several extensions to the standards including: weak pairs, string ports, property lists, futures, pretty printer, debugger, compiler and multitasking. The latest version for the Mac running the normal System/Finder is MacGambit release 2.2.1.