|Sussman and Steele||December 22, 1975||1||The SCHEME Reference Manual|
Section 1: The SCHEME Reference Manual
SCHEME is essentially a full-funarg LISP.
LAMBDA expressions need not be
*FUNCTIONed when passed as arguments or returned as values; they will evaluate to closures of themselves.
All LISP functions (i.e.,
LSUBRs, but not
MACROs) are primitive operators in SCHEME, and have the same meaning as they have in LISP. Like
LAMBDA expressions, primitive operators and numbers are self-evaluating (they evaluate to trivial closures of themselves).
There are a number of special primitives known as
AINTs which are to SCHEME as
FSUBRs are to LISP. We will enumerate them here.
- This is the primitive conditional operator. It takes three arguments. If the first evaluates to non-
NIL, it evaluates the second expression, and otherwise the third.
- As in LISP, this quotes the argument form so that it will be passed verbatim as data. The abbreviation "
'FOO" may be used instead of "
- This is analogous to the MacLISP
DEFUNprimitive (but note that the
LAMBDAmust appear explicitly!). It is used for defining a function in the "global environment" permanently, as opposed to
LABELS(see below), which is used for temporary definitions in a local environment.
DEFINEtakes a name and a lambda expression; it closes the lambda expression in the global environment and stores the closure in the LISP value cell of the name (which is a LISP atom).
- We have decided not to use the traditional
LABELprimitive in this interpreter because it is difficult to define several mutually recursive functions using only
LABEL. The solution, which Hewitt [Smith and Hewitt] also uses, is to adopt an ALGOLesque block syntax:
(LABELS <function definition list> <expression>)
This has the effect of evaluating the expression in an environment where all the functions are defined as specified by the definitions list. Furthermore, the functions are themselves closed in that environment, and not in the outer environment; this allows the functions to call themselves and each other recursively. For example, consider a function which counts all the atoms in a list structure recursively to all levels, but which doesn't count the
NILs which terminate lists (but
NILs in the
CARof some list count). In order to perform this we use two mutually recursive functions, one to count the car and