MTS 8: LISP and SLIP in MTS
June 1976
10 CONTINUE
ASSIGN 20 TO LOOP
M = N
IFACT = INTGER(VISIT(LOOP,NEWTOP(REALL(M),W(1))))
RETURN
C
C recursive loop
C
20 CONTINUE
M = M-1
IF(M.EQ.0) GO TO 40
IFACT = INTGER(VISIT(LOOP,NEWTOP(REALL(M),W(1))))
IFACT = IFACT*INTGER(TOP(W(1)))
30 CONTINUE
CALL TERM (REALL(IFACT),RESTOR(1))
40 CONTINUE
IFACT = 1
GO TO 30
END
The first VISIT function enters the loop at statement 20. The
decreasing values of N are pushed down on the argument stack by
consecutive executions of the second VISIT function. When finally, with
N = 0, TERM passes the control back to the first VISIT function, the
stacks have been popped off and all housekeeping duties accomplished.
Another illustrative example of recursion is the SLIP function
LSTEQL(LA,LB). In the following sample program, it checks whether two
list structures are identical. The function PARMT2(A,B) is used. It
places A and B on the top of public lists W(1) and W(2) and delivers the
value A.
FUNCTION LSTEQL(LISTA,LISTB)
DOUBLE PRECISION PARMT2,TOP,ADVLWR,REALL
DOUBLE PRECISION A,W,LISTA,LISTB,DATUMA,DATUMB
INTEGER VISIT,READLA,READLB
COMMON /PUBLIC/ W
DIMENSION W(100)
C
C... Recoded by B. Herzog, May 1974
C
C
C The two input parameters to this function are both
C names of list structures. The objective of this
C function is to determine whether or not these
C list structures are equal. If they are, the value
C of the function is zero, otherwise it is nonzero.
C The two list structures are equal if they have
C identical structures, i.e., sublist names
C appearing in corresponding places within both
C structures, and if corresponding elements
C appearing in both structures are identical.
C
138 SLIP

MTS 8: LISP and SLIP in MTS
June 1976
LSTEQL=0
ASSIGN 100 TO L100
LSTEQL=VISIT(L100,PARMT2(LRDROV(LISTA),LRDROV(LISTB)))
RETURN
100 CONTINUE
READLA=INTGER(TOP(W(1)))
READLB=INTGER(TOP(W(2)))
C...
200 CONTINUE
IF (LSTEQL.NE.0) GO TO 800
C... Advance the readers on both lists.
DATUMA=ADVLWR(READLA,IFLAGA)
DATUMB=ADVLWR(READLB,IFLAGB)
C... Inquire if the structures are the same.
C... IFLAGA or IFLAGB will be nonzero if a HEADER
C... is encountered on the corresponding list.
IF (IFLAGA.NE.IFLAGB) GO TO 600
C... So the structures are the same. Have the readers
C... returned to the HEADER?
IF (IFLAGA.NE.0) GO TO 500
C... No. Now examine the DATUM returned from each list.
C... Are they list names?
C... NAMTST yields zero if Datum is name of a list.
IF ((NAMTST(DATUMA).EQ.0)
.AND.(NAMTST(DATUMB).EQ.0)) GO TO 300
C... Not list names! But does DATUMA.EQ.DATUMB?
IF (DATUMA.NE.DATUMB) LSTEQL=-1
GO TO 400
300 CONTINUE
C... So both are list names; keep advancing.
CALL PARMT2(LRDROV(DATUMA),LRDROV(DATUMB))
LSTEQL=VISIT(L100)
IF (LSTEQL.EQ.0) GO TO 100
GO TO 400
400 CONTINUE
500 CONTINUE
GO TO 700
600 CONTINUE
C... Arrive here if the list structures are not equal.
LSTEQL=-1
GO TO 700
700 CONTINUE
800 CONTINUE
IF ((LSTEQL.EQ.0).AND.(IFLAGA.EQ.0)) GO TO 900
C....
CALL IRARDR(TOP(W(1)))
CALL IRARDR(TOP(W(2)))
CALL TERM(REALL(LSTEQL),
RESTOR(2))
900 CONTINUE
GO TO 200
END
SLIP 139
Previous Page Next Page