MTS 8: LISP and SLIP in MTS
June 1976
(4) If either DEFN1 or DEFN2 is NIL, then that portion of the BUG
will be ignored and the function A will be invoked or exited
without intervention.
Example:
A BUG is put on the function COUNT, to trace the entry and exit,
and to print out the arguments.
(DEFUN COUNT (L N) (COND ((NOT L) N)
((COUNT (CDR L) (ADD1 N)))))
(DEFINE (COUNT BUG ((FLAMBDA (ARGS)
(PRINT ’ENTRY-TO-COUNT)
(PRIN1 ’ARGUMENTS:)
(PRIN1 ARGS) (TERPRI))
.(LAMBDA (RET)
(PRINT ’EXIT-FROM-COUNT)
(PRIN1 ’VALUE:) (PRIN1 RET)
(TERPRI)))))
Arrays ______
The basic form of a LISP array definition is
(DEFINE (A ARRAY (A1...AN) FILL))
This is the basic form of a LISP array definition. In this example, A
will be defined as an N-dimensional array with subscript bounds A1...AN.
A1...AN must be atoms whose VALUEs are integers. If a fourth argument,
FILL, is given, the initial value of each element in the array will be
set to that structure. Otherwise, each element in the array is
initially set to NIL.
An array definition associated with an atom operates like a function
definition for that atom. A pointer to the appropriate access code is
stored on the property-list of the atom, under the indicator SUBR. The
value of an array element is obtained by invoking the "function", with
the appropriate subscripts as arguments. For example,
(A 1 (ADD 3 5) (CADR ’(B 3)))
will evaluate to the array element A(1,8,3). It should be noted that
since an atom may be defined as a function in only one way at a time,
defining A as an array will negate any other function definition A may
have had, and defining A as a function will negate the definition of A
as an array.
To set the value of an array element, the SETA function is used:
42 LISP

MTS 8: LISP and SLIP in MTS
June 1976 Page Revised February 1979
(SETA (A 2 (ADD 2 2) 2) ’(B C D))= (B C D)
and the array element A(2,4,2) will be set to the list (B C D).
The value of an array element may be any LISP structure.
Note: The user may conveniently define an array and use his own
hash-coding algorithm to compute the subscripts as follows:
(DEFINE (A ARRAY (8000)))
To obtain an element of A:
(A (HASHFN CODE1...CODEN))
To set an element of A:
(SETA (A (HASHFN CODE1...CODEN)) VALUE)
HASHFN may be any LISP function which returns a numeric atom as its
value, or may be an external routine called from LISP.
Calling External Routines from LISP ___________________________________
LISP provides the option of calling user-written or library subrou-
tines. The major purpose of this feature is to allow the use of complex
numeric functions, hash functions, etc., which would be slower if
written in LISP.
The basic form used to define external subroutines in LISP is:
(DEFINE (FN SUBR,NSUBR,FSUBR (N FILENAME ENTRY-NAME)))
FN is an atom which will become the LISP name of the external function.
FILENAME is the name of an MTS file from which the external code is to
be loaded. ENTRY-NAME specifies which entry point in an object file, or
which subroutine in a library file, is to be associated with the LISP
function name FN. If no ENTRY-NAME is given for an object file, the
default MTS entry point will be used (see the loader description in MTS
Volume 5 for a description of entry point determination). If no
ENTRY-NAME is given for a library file, an error will be generated. If
the ENTRY-NAME given is already in memory, nothing will be loaded, and
the LISP function FN will be defined to be the ENTRY-NAME function. N
specifies the type of calling conventions to be used, and must be set at
0, 1, 2, 3, or 4.
N=0 signifies that LISP internal SUBR calling conventions will be
used. Any number of arguments may be given, and these may be
any LISP structures. This external mode is for the use of
system programmers who might wish to write extensions of the
LISP 43
Previous Page Next Page