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

MTS 8: LISP and SLIP in MTS
June 1976
Other Forms of LAMBDA-Expressions _________________________________
There are two other alternate forms of LAMBDA-expressions, which
allow the user to give explicit definitions of N-type functions.
The first of these is the NLAMBDA-expression. The basic spread and
no-spread forms of NLAMBDA-expresssions are as follows:
(NLAMBDA (A1...AN) S1...SN)
(NLAMBDA A S1...SN)
The NLAMBDA-expression operates like an ordinary LAMBDA. The only
exception is that the argument-designators themselves, rather than their
values, are used as the arguments to the NLAMBDA. For example,
((NLAMBDA (X) (CDR X)) (A B C)) = (B C)
((NLAMBDA A (CAR (ARG 1))) ’(A B C)) = QUOTE
The second alternate form of LAMBDA-expression is the FLAMBDA. The
basic forms of FLAMBDA-expression are as follows:
(FLAMBDA (A) S1...SN)
(FLAMBDA A S1...SN)
The argument-passing conventions for FLAMBDA-functions are slightly
different than for LAMBDA and NLAMBDA-expressions. The FLAMBDA-
expression must always have exactly one dummy argument. In the case of
a spread-type FLAMBDA, this single argument is bound to a list of all
the argument-designators. In the case of a no-spread type FLAMBDA, the
dummy argument is always bound to the number 1, and the function (ARG 1)
will return the list of all the argument-designators. For example,
((FLAMBDA (A) A) X Y Z) = (X Y Z)
((FLAMBDA A (ARG A)) X Y Z) = (X Y Z)
It is important to be aware of the effect of applying or mapping the
three types of functions. The argument-designators to APPLY and APPLY1
are always EVALed before being passed to these functions, and will not
be evaluated again. Thus, for the purposes of APPLY, APPLY1, MAP, etc.,
the differences between LAMBDA and NLAMBDA-functions disappear. How-
ever, for FLAMBDA-type functions, the arguments given are made into a
list when used with APPLY1, or left in their list form in the case of
APPLY. Thus, when these functions are APPLYed they always receive a
single argument. The following examples illustrate the process:
(APPLY ’(LAMBDA (X Y Z) (LIST X Y Z)) ’(A B C)) = (A B C)
(APPLY ’(NLAMBDA (X Y Z) (LIST X Y Z))
’(A B C)) = (A B C)
(APPLY ’(FLAMBDA (X) (LIST X))
’(A B C)) = ((A B C))
LISP 37
Previous Page Next Page