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