MTS 8: LISP and SLIP in MTS
June 1976
yields the depth to which the Reader has descended into the associated
list structure.
Other routines include the function
REED(NRD)
which returns as value the contents of the SLIP-cell to which the Reader
NRD points. It can be considered a null advance function compared to
the following three routines.
The function
LVLRVT(NRD)
causes the Reader NRD to ascend back to the main list from any current
position in a list structure. After the execution of this routine, the
Reader points to that SLIP-cell on the main list from which the descent
originated. If the Reader initially points to a main-list element no
action is taken. When LVLRVT is used as a function the returned value
is that of the argument. Thus, LVLRVT can be nested within another
function that also requires the NRD argument.
The function
LVLRV1(NRD)
has a similar role, but it makes the Reader ascend only one level.
Again, no action is taken if the Reader initially points to the main
list.
The function
INITRD(NRD)
goes linearly along the list it is currently pointing to until it hits
the Header cell.
A Reader can be initialized from any state by
IDUM=INITRD(LVLRVT(NRD))
Here LVLRVT brings the Reader to the "surface" (i.e., to the main list),
and INITRD makes it point to the Header of that list.
There is no theoretical limitation concerning the number of Readers
appointed to and traversing concurrently the same list structure. A
copy of the Reader can be made by using the function
LRDRCP(NRD)
The name of the new Reader is delivered as its value.
132 SLIP

MTS 8: LISP and SLIP in MTS
June 1976
The function
LSTPRO(LST,NRD)
searches the Reader stack with alias NRD until it finds a cell that is
associated with, or appointed to, the list LST. The returned value is 0
if the search is successful; otherwise it is -1.
This function is needed when a sublist references itself or a
higher-level list. Clearly, in this case, structural advancing would
never terminate. The function LSTPRO discovers such a situation. Note
that the advance functions described below do not use LSTPRO and,
therefore, fail in the case of recursive list structures.
The best schema to define the advance functions is
|E|
|L| | | |L|
ADV | | |N| | | (NRD,IFLAG)
|S| | | |R|
|W|
One letter from each column must be chosen to derive an advance
function. ADVLWR and ADVSWL are representative of the twelve possible
cases. In each case, the Reader designated by NRD, which was set up
beforehand, is made to point to the next unit. The advancement is
linear (L) or structural (S); the next unit is a datum element (E), a
sublist name (N), or a word containing either of these two types of
elements (W); finally, the direction is to the left (L) or right (R).
The returned value of these functions is the datum of the SLIP-cell
to which the advanced Reader points. The INTEGER parameter IFLAG stays
0 as long as the advancement does not reach a Header. With linear
advancement, when a Header is reached, IFLAG assumes the value -1. With
structural advancement, when a Header is reached, the Reader ascends
into a superlist if it can. When the Reader already points to the main
list, no further ascent is possible; and IFLAG becomes -1. Thus,
advancement is not terminated unless the whole list (linear case) or the
whole list structure (structural case) has been systematically and
selectively traversed. When IFLAG = -1, the returned values are the
contents of the datum word of the Header cell and, therefore, are
essentially garbage.
The following program segment searches a list structure with alias
LST determining whether any of its elements are identical with the
FORTRAN word SYMBOL.
DOUBLE PRECISION ADVSER,DATUM,SYMBOL
LRDR=LRDROV(LST)
10 CONTINUE
DATUM=ADVSER (LRDR,IFLG)
IF (IFLG.NE.0) GO TO 20
IF (DATUM.NE.SYMBOL) GO TO 10
SLIP 133
Previous Page Next Page