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 QUOTE
d, FUNCTION
ed, or *FUNCTION
ed when passed as arguments or returned as values; they will evaluate to closures of themselves.
All LISP functions (i.e., EXPR
s, SUBR
s, and LSUBR
s, but not FEXPR
s, FSUBR
s, or MACRO
s) 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 AINT
s which are to SCHEME as FSUBR
s are to LISP. We will enumerate them here.
IF
-
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. QUOTE
-
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 "(QUOTE FOO)
". DEFINE
-
This is analogous to the MacLISP
DEFUN
primitive (but note that theLAMBDA
must appear explicitly!). It is used for defining a function in the "global environment" permanently, as opposed toLABELS
(see below), which is used for temporary definitions in a local environment.DEFINE
takes 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). LABELS
-
We have decided not to use the traditional
LABEL
primitive in this interpreter because it is difficult to define several mutually recursive functions using onlyLABEL
. 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
NIL
s which terminate lists (butNIL
s in theCAR
of some list count). In order to perform this we use two mutually recursive functions, one to count thecar
and