MTS 8: LISP and SLIP in MTS
June 1976
If no Ei matches EQUTHING, then FAIL is
evaluated, and its value is returned. It is
important to understand that the last argument
of SELECT is always treated as a form to
evaluate in case of failure, and never as a
(E1 S1...SN) type of expression. Thus, a FAIL
expression must be given.
(SELECT (GET ’BOOK ’COLOR)
(’BLUE (BLUEFN ’BOOK))
(’RED (REDFN ’BOOK))
(’GREEN (GREENFN ’BOOK))
(PROGN (PRINT ’(ERROR: BOOK ILLEGAL COLOR))
(ERRCOLOR ’BOOK)))
(PROG LA S1...SN)
(GO A) The PROG function allows the LISP user to
write subroutine-like sequences of LISP code,
with branching, and with the ability to exit
and return a value at any point.
LA is a list of local or PROG variables. The
PROG variables are bound to NIL upon entry to
the PROG, and unbound to their previous values
upon exit from the PROG. Thus, the PROG
variables may be used within a PROG as though
they were distinct from anything outside the
PROG. Note that this "protection" of PROG
variables applies only to their VALUEs. If
the property list of a PROG variable is
changed within a PROG, the change will not be
undone upon exit from the PROG. The PROG
variable list may be NIL, but it may not be
omitted.
S1...SN is a sequence of forms to be evaluated
in order. However, if any of these forms are
atoms, they are not evaluated, but rather are
interpreted as statement labels. If a form
(GO A) appears in the PROG, and A is used as a
statement label in the PROG, then evaluating
(GO A) causes the flow-of-control to be trans-
ferred to the form which appears after the
label A.
If the flow-of-control "drops through" the
last form of the PROG, then the value of that
form will be returned as the value of the
PROG. However, if the last form of the PROG
is an atom, then the atom itself, rather than
its VALUE, is returned as the value of the
PROG.
32 LISP

MTS 8: LISP and SLIP in MTS
June 1976
If at any point within a PROG, a form (RETURN
S) is evaluated, then PROG immediately exits,
and returns the value of S.
Note: GO is, like PROG , an N-type function.
Thus, (GO A) will cause a branch to the form
labeled by the atom A. However, if GO is
given a nonatomic argument, it will EVAL this
argument, and then attempt to branch to the
result.
(GO (CAR A)) will evaluate (CAR A), and if the
result is an atom, will branch accordingly.
If the result is not an atom, GO will EVAL it
in turn, and continue the process until an
atom is found.
(RETURN S STACKID) The RETURN function can be used in two modes.
When (RETURN S) is evaluated and no second
argument is given, it will cause an immediate
return from the dominating PROG, and the value
of the PROG will be S. If a return of this
type is evaluated, but there is no dominating
PROG, an error will be generated.
(RETURN S STACKID) allows the user to return
from any dominating LISP evaluation, and the
value returned will be S. If STACKID is a
positive integer N, the return will be made
from the EVAL level N deep, starting at the
top level of LISP. Thus, (RETURN ’A 1) will
always cause a return to the top level of
LISP, and A will be printed. If STACKID is a
negative integer -N, the return will be made
from the Nth previous EVAL level, starting
with -1 at the level before the call to
RETURN. Thus, (CAR (CDR (CAR (CDR (RETURN ’(A
B) -3))))) = A.
If STACKID is not a number, then all outstand-
ing EVAL forms will be examined, from most
recent to least recent, and the return will be
made from the first form found whose CAR is
EQUAL to STACKID. Thus, (RETURN S ’PROG) has
the same effect as (RETURN S).
If STACKID does not identify an existing EVAL
form, either because it is too large a number
or because it does not match the CAR of any
outstanding form, an error will be generated.
The following example program searches a list for atoms and prints
out each atom, along with its syntactic depth of occurrence. The
LISP 33
Previous Page Next Page