MTS 8: LISP and SLIP in MTS
June 1976
WRITE (6, 100) SYMBOL
100 FORMAT (5X,A8,15H IS IN LIST LST)
GO TO 30
20 CONTINUE
WRITE (6,110) SYMBOL
110 FORMAT (5X,A8,19H IS NOT IN LIST LST)
30 CONTINUE
CALL IRARDR (LRDR)
As can be seen, the use of the advance functions must be preceded by
the creation of the Reader. Similarly, after the task has been
accomplished, the programmer should erase the Reader.
Suppose we wish to write a subroutine that searches a list structure
with alias LST for all occurrences of the symbol S. If found, S is
removed; otherwise nothing happens.
SUBROUTINE SEARCH (LST,S)
DOUBLE PRECISION ADVSWL,ADVSWR,X,S,LST
LSTRDR = LRDROV (LST)
100 CONTINUE
X = ADVSWR (LSTRDR,IFLG)
IF(IFLG.NE.0) GO TO 200
IF(X.NE.S) GO TO 100
IPOINT = LPNTR (LSTRDR)
CALL ADVSWL (LSTRDR,IFLG)
CALL DELETE (IPOINT)
GO TO 100
200 CONTINUE
CALL IRARDR(LSTRDR)
RETURN
END
Note that the second call to the advance function in the opposite,
left, direction is necessary because of the DELETE operation.
The following three examples illustrate the use of these functions.
WHATS = ADVLWR(KADR1,IFLAG1)
modifies the LPNTR field of the Reader with alias KADR1 to point to the
cell immediately to the right of the one it pointed to before execution
of the function. If this new cell is the Header of the list involved,
IFLAG1 is set to -1, and WHATS is essentially garbage. Otherwise,
IFLAG1 is 0, and WHATS contains the datum of the SLIP-cell currently
pointed to by the Reader. Note that no descent is made to a sublist
even if a reference to it is encountered.
The statement
IUP = INTGER(ADVSNL(NRD2,IFLAG2))
134 SLIP

MTS 8: LISP and SLIP in MTS
June 1976
assigns to IUP the next accessible alias, if available, on the list
structure with Reader NRD2. If the Reader originally points to one, a
descent is made. If the original level corresponds to a terminal list
with no more sublists, an ascent is made. IFLAG2 stays 0 as long as the
assignment is successful. When the Reader finally points to the Header
of the main list, IFLAG2 becomes -1. The advances are made in the left
direction.
Finally,
THERIN = ADVSER(NRD3,IFLAG3)
produces the next nonname datum to the right. Descents and ascents are
made whenever needed. IFLAG3 is 0 until the Reader no longer points to
the Header of the main list. It then becomes -1.
In addition to the Reader and the advance functions, another simpler,
less time-consuming, and in some applications completely satisfactory,
technique is available. The sequence operations, the basis of this
technique, use a Sequence Reader, which is a single FORTRAN word, rather
than a stack of special SLIP-cells. Single-level traversal and descent
to arbitrary depth are possible; but since no historical record of the
descents is kept, no ascent can take place.
The function SEQRDR via the code
SRDR = SEQRDR(LST)
sets up a single INTEGER computer word SRDR as a Sequence Reader for the ________ ______
list LST. This Sequence Reader contains the cell name of the SLIP-cell
currently pointed to by the Reader. A sequence advance operation
indicates the cell name to which the advanced Sequence Reader points
next.
The returned value of the sequence functions is again the datum of
the SLIP-cell being examined. The linear sequence functions
SEQLR(SRDR,IFLAG)
and
SEQLL(SRDR,IFLAG)
are analogous to the linear advance functions ADVLWR and ADVLWL,
respectively. SRDR is the Sequence Reader. IFLAG is set to -1, 0, or
+1 if the retrieved SLIP-cell contains a datum, contains a sublist name,
or is a Header cell, respectively.
The structural sequence functions
SEQSR(SRDR,IFLAG)
SLIP 135
Previous Page Next Page