MTS 8: LISP and SLIP in MTS
June 1976
Note: In general, the term "LAMBDA-expression" is a generic term
including the NLAMBDA and FLAMBDA-expressions.
Named LAMBDA-Expressions (LABEL-Expressions) ____________________________________________
LISP provides a special syntax for writing LAMBDA-expressions which
are capable of calling themselves. This is the LABEL-expression. The
basic form of a LABEL-expression is:
(LABEL NAME LAMBDA-EXP)
where NAME may be any atom. NAME is first bound to the LAMBDA-
expression which is the second argument of the LABEL-expression. The
evaluation continues as though the LAMBDA-expression had been given.
The effect is that NAME is temporarily defined as the LAMBDA-expression,
provided that NAME is not already defined as a function within the
system.
Thus, within the LAMBDA-expression, explicit calls to NAME may be
made, which will invoke the LAMBDA-expression recursively. For example,
((LABEL COUNT (LAMBDA (L N)
(COND ((NOT L) N)
((COUNT (CDR L) (ADD1 N))))))
’(A B C D E) 0) = 5
This LABEL-expression temporarily defines a function COUNT, which will
return the sum of its second argument and the number of elements in its
first argument.
Accessing Defined Functions ___________________________
When an atom is to be used as a function name, a link to the function
definition is maintained on the property-list of that atom. The
following special system indicators are used to mark function
definitions:
SUBR
NSUBR
FSUBR
EXPR
BUG
SUBR, NSUBR, and FSUBR are indicators which mark the three types of
built-in LISP functions. SUBRs take their arguments EVALed, like
LAMBDA-functions; NSUBRs take their arguments without evaluation as do
NLAMBDA-functions, and FSUBRs take their arguments in a list, like
38 LISP

MTS 8: LISP and SLIP in MTS
June 1976
FLAMBDA-functions. The property-values associated with these indicators
are pointers to the machine code for those functions. An attempt to
print out one of these links will merely cause an asterisk (*) to be
printed.
EXPR and BUG are the indicators used to mark the two types of
user-defined functions. The property-value associated with an EXPR
indicator will be a function specification (usually but not necessarily
a LAMBDA-expression) which will be invoked when the "parent" atom is
used as a function name.
If several special system indicators are on the property-list of the
same atom, the first (and most recent) one will be used as the function
definition for that atom.
Note: There is nothing to prevent the user from modifying or
destroying the special system properties on the PLIST of an atom. In
fact, since the PLIST of an atom is the CDR of the atom, the user may
access this list just as any other list. This may often be a good
method of making corrections to a user-defined function. However,
modifying or destroying the links to built-in LISP functions should be
done carefully, if at all.
Defining New Functions in LISP ______________________________
DEFUN and DEFINE are two functions for defining new functions in
LISP.
DEFUN is an N-type function which provides an easy way for the user
to define one new LISP function by the usual method of putting a
LAMBDA-expression on its property-list. The basic form of DEFUN is:
(DEFUN NAME TYPE ARGLIST S1...SN)
NAME is the name of the function being defined. TYPE must be EXPR,
NEXPR, or FEXPR. If TYPE is omitted, EXPR is assumed. ARGLIST is a
list of dummy arguments, or NIL, for a spread-type function; or a single
atom for a no-spread-type function. S1...SN is the body of the
function.
If TYPE is EXPR, a LAMBDA-expression is created.
If TYPE is NEXPR, an NLAMBDA-expression is created.
If TYPE is FEXPR, an FLAMBDA-expression is created.
DEFUN always places the created LAMBDA-expression on the property-list
of NAME under the indicator EXPR. The value returned from DEFUN is the
atom NAME. If TYPE is omitted, then ARGLIST may not be EXPR, NEXPR, or
FEXPR. For example,
LISP 39
Previous Page Next Page