MTS 8: LISP and SLIP in MTS
Page Revised February 1979 June 1976
| ((LAMBDA (X) (CDR X)) ’(A B C)) = (B C)
Note: When it is stated that an atom is bound to some value, this
means that its present VALUE is saved, and it is set to the new value.
When the atom is unbound, its previous VALUE is restored. Within the
scope of a LAMBDA-expression, the dummy arguments have as their VALUEs
the arguments of the function. For example, within the LAMBDA-
expression above, the VALUE of X is (A B C).
Note: The number of arguments to a LAMBDA-expression, as for any
other function, must be the same as the number of dummy arguments, or an
error will result. The dummy argument list may be NIL, in which case
the function takes no arguments, but it may not be omitted.
The No-Spread Form of a LAMBDA ______________________________
Another form of LAMBDA-expression which takes an indefinite number of
arguments may be defined. The basic form of the no-spread LAMBDA-
expression is
(LAMBDA A S1...SN)
Here the dummy argument list is replaced by a single non-NIL atom.
When a no-spread LAMBDA is executed, the dummy argument A is bound to
the number of arguments which were given.
The value of any particular argument may be obtained by calling the
function ARG, with the number of the desired argument. Thus, (ARG 1)
returns the first argument, (ARG 3) the third argument, etc. Calling
ARG with a number greater than the given number of arguments will
generate an error.
Because a no-spread LAMBDA-expression may occur within the scope of
another no-spread LAMBDA-expression, the function ARG takes an optional
second argument which, if given, must be EQ to the dummy argument of a
dominating no-spread LAMBDA. For example,
((LAMBDA A (ARG 1 ’A)) ’(C D)) = (C D)
If no second argument is given to ARG, then the immediately dominating
no-spread LAMBDA is implied.
The following function will return a list of the CARs of all of its
arguments.
(LAMBDA C (PROG (X N)
(SETQ N 1)
A (COND ((GREATERP N C) (RETURN X))
((SETQ X (APPEND X (CAR (ARG N))))))
(SETQ N (ADD1 N))
(GO A))
36 LISP