MTS 8: LISP and SLIP in MTS
June 1976
(DEFUN SAMPLE 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)))
This creates a function called SAMPLE, which returns a list of the CARs
of all of its arguments. SAMPLE takes an indefinite number of
arguments, or no arguments.
(SAMPLE) = NIL
(SAMPLE ’(S R T) ’(P Q) ’(R)) = (S P R)
DEFINE is the basic function for defining and naming new LISP
functions. The basic form of DEFINE is:
(DEFINE (NAME TYPE DEFN)...(NAME TYPE DEFN))
DEFINE is an N-type function which takes an indefinite number of
definitions, DEFN, as arguments. NAME is always an atom, which is the
name of the entity being defined. TYPE may be EXPR, BUG, ARRAY, SUBR,
NSUBR, or FSUBR, or may be omitted, in which case EXPR is assumed.
For an EXPR or BUG, the DEFN given is put on the PLIST of NAME
exactly as it appears. Thus, to DEFINE an EXPR, the entire LAMBDA-
expression must be written out. The form and meaning of BUG definitions
will be explained in the next subsection.
The ARRAY and SUBR definitions require special parameters which
respectively define LISP arrays and create linkage to external subrou-
tines. The form and meaning of these definitions is explained in the
subsections "Arrays" and "Calling External Routines from LISP."
The value returned from DEFINE is the name defined if only one
definition was given, or a list of the names defined if more than one
was given. For example,
(DEFINE (TEST EXPR (LAMBDA (Y) (PRINT Y)))) = TEST
This defines a function TEST which merely prints its argument.
Note: DEFUN and DEFINE, which place properties on the PLISTs of
atoms, do not work in the same way as PUT. They compare the current
indicator being placed on the PLIST with the first indicator already on
the PLIST; if they are the same, the PVAL of that indicator is replaced
with the new definition. If the current indicator does not match the
first one on the PLIST, the new property is merely placed in front of
it. This process guarantees that the most recent function definition of
an atom will be the active one.
40 LISP