To start up UMASS scheme type scheme as a Unix command. You will get a message like this:
Sussex Poplog (Version 14.5 Tue Feb 22 15:01:28 WET 1994) UMASS Scheme (Version 1.0) initialising X windows Sussex XVed (Version 2.0 (motif), SCHEME Tue Sep 12 12:14:16 EDT 1995) X Server: MIT X Consortium initialising X windows
[Note for experts: getting UMASS Scheme depends on an alias in the class .cshrc file, which itself depends on your own ~/.cshrc file. If you change this file, you may find yourself running a version MIT Scheme which does NOT accord with the IEEE standard required for this class.
UMASS Scheme is implemented under the Sussex Poplog system developed at Sussex University (Falmer UK), and employs the X-window system developed at MIT (Cambridge MA). ]
If you are logged in in the EDLAB, you will get a version which is customised for running under X-windows. In this version, you will be able to edit and test programs entirely within UMASS Scheme system if you wish.
If you are logged in remotely, for example from home, and do not have an X-server on your local machine, you will get a version of UMASS Scheme which is customised for running under a terminal emulator. If your emulator matches a VT100 terminal, this should be OK, but you may need to set the term environment variable before you run your Scheme. If Scheme is unhappy with your terminal it will say so.
setenv term vt100
If you are logged in remotely from a machine which is running an X-server, for example another workstation in UMASS, or your own machine running an X-server using the ppp protocol, you should do:
setenv DISPLAY mymachine:0.0
where mymachine is the net-address of the machine you are logged in on. This will allow UMASS Scheme to open windows on your machine.
Under X-windows, a small "control panel" will pop-up when you start Scheme. This has a box labelled "File:". This contains the name of a default file ("unnamed.scm") that you can edit using the built-in VED editor. If you want to change this, put the mouse in the box, drag the mouse along the length of the name - it will now reverse its colours. Then type in the name of the file you want to edit, and hit the Do Edit button. After a brief pause a new window will appear with your file (possibly empty) in it.
If it is a file to contain text in the Scheme language, the name should end with ".scm".
There is also "Exit" button to kill the Scheme system.
Each edit window contains a "menu-bar" across the top. This is used in a style akin to that of the Macintosh. Currently this has the following menus attached:
Note that most of the file options use a "File Tool" which allows you to select the file to operate on interactively. This looks a bit complicated, but you can always type the name of the file you want in the Selection: slot, and hit the "Edit" button.
You can also select a "range" of text. To do this, hold down the control key (ctrl) and use left mouse button to select a number of lines of text. The selected range is indicated by a black line that appears down the left of your screen.
A Search function is also provided.
At the bottom of the edit menu is "Justify current procedure". This indents the text of a Scheme function correctly. You should always try to write your Scheme text correctly indented.
Additional help with editing is found under the "287" menu. This online material is found in the directory $cs287/public_html.
XVed*font: 7x12 # The default size - rather small for some. XVed*font: 9x15 # A bigger size, which you may like better.
You can also change the font of a particular window by doing
All expressions and other constructs of the Scheme language which occur in these lectures are set in a typewriter font, An example of typewriter font is (define pi 3.14159) .
Typewriter fonts are characterised by being fixed-width (every letter occupies the same amount of space on the page). In the HTML browser which is being constructed to let you view these lectures from within UMASS Scheme, Scheme expressions will appear in red, since the VED editor always uses a single fixed-width font and provides no means of distinguishing text by using a different font, only by making variants on a given font.
Where it is important to make an expression of the language stand out, it will be placed indented as a line or lines of text separated from the English commentary. For example:
(define pi 3.14159)
Grammatical constructs are specified using a bold version of the typewriter font. For example, we specify one form of the Scheme define statement by
(define variable expression)
Here, because variable is in a bold font it means that you can write any Scheme variable in place of it; likewise because expression is in a bold font it means that you can write any Scheme expression in place of it. So, the previous statement:
(define pi 3.14159)is an instance of the grammatical form
(define variable expression)
Scheme operates on the usual simple data-objects, that is to say data-objects that can best be thought of as having no internal structure.
integers: These are of arbitrary precision that is they are only limited in size by the total amount of memory you have!
rationals: Scheme can and will compute with fractions. If you divide one integer by another you will get a rational. You should usually avoid rational computations, unless you are doing symbolic algebra!
reals: These are represented by floating point numbers.
booleans: These are #f (false) and #t (true). [NOTE for experts: unlike non IEEE Schemes and most Lisps, the empty list '() is not a false truth value.]
23 is an integer 3.4 is a real 3/4 is a rational (WARNING - UMASS Scheme does not currently input rationals but it will generate them and print them out).
A scheme variable is a sequence of letters (a..z A..Z) or digits (0..9) or signs (+ - * / ...) which are terminated by "white-space" or by certain special characters, of which parentheses are the most important. In fact, most combinations of non-whitespace characters which Scheme does not recognise as being a number are treated as a variable. Usually, people will choose helpful names for variables.
For example the following are variables:
x y x_23 34x the-fat-cat + +1
Warning - Scheme gives some variables initial values, for example +, *, / . It is not a good idea to use these variables for your own purposes!
Variables usually have values. We say that a variable is bound to a value when it is associated with the value. Scheme has a statement which creates a new variable and binds it to the value of an expression
(define variable expression)
For example:
(define pi 3.14159)
binds the variable pi to have the value 3.14159
Expressions have a very uniform syntax in Scheme. An expression can be a constant or a variable, or it can be a sequence of expressions enclosed in parentheses (sometimes called a combination).
In the case of a combination, the first expression is regarded as a function while the others are its arguments. Thus:
(+ 3 4)
is an expression, whose function is '+' and whose arguments are 3 and 4.
When Scheme evaluates an expression of this form, it evaluates the function and arguments, and then applies the function to the arguments. Evaluating the above expression we get
7
(- 5 4)
means "the result of subtracting 4 from 5", or in ordinary mathematical notation 5-4.
A more complicated example is:
(+ 3 (* 4 5))
Here we evaluate (* 4 5) to get 20, and then add 3 to get 23.
Well, actually functions are pieces of machine code (in effect subroutines for those who have taken CMPSCI 201). So the value of the variable '+' is a piece of code for doing addition.
[Note you can actually redefine Scheme standard functions. This is NOT recommended for novices, for you may lose important capabilities]
A Scheme function is specified by the syntax
(lambda formals body)
here formals is (usually) a sequence of variables enclosed in parentheses, and body is a sequence of expressions. For the functional use of Scheme, only one expression is needed in the body.
Note that this is not an application of the function lambda, but is what is called a "special form" in Scheme.
For example
(lambda (x) (* x x))
is the function which squares its argument. So
( (lambda (x) (* x x)) 3)
evaluates to 9.
The rule for evaluation of a lambda-function applied to arguments is to (a) evaluate all the arguments, and (b) strip off the 'lambda' and substitute the values of each argument for the corresponding formals, (c) evaluate the body of the lambda with the values substituted.
( (lambda (x) (* x x)) (+ 3 4))
Evaluate the argument
( (lambda (x) (* x x)) 7)
Strip and substitute for corresponding formals (x=7) :
(* 7 7)
Evaluate body
49
This may seem a funny way of defining functions - in Pascal we would give the corresponding function a name, like "square". In Scheme, this is easily done
(define square (lambda(x) (* x x)) )
Scheme responds:
<Compiled function: square>
and now we can use it
(square 4)
Scheme responds:
16
An example of a lambda expression with more than one argument is
(lambda (x y) (+ x (* 2 y))
And an example of its use is:
((lambda (x y) (+ x (* 2 y))) (+ 4 3) 5)
Evaluate the arguments
((lambda (x y) (+ x (* 2 y))) 7 5)
Strip and substitute, x=7, y=5:
(+ 7 (* 2 5)))
and evaluate
(+ 7 10)
17
This is accessed by hitting the "Debugger" button on the Scheme Control Panel. It is operated by a panel which contains the following buttons:
The function application (load "file") will load any file as Scheme program.