Page:Scheme - An interpreter for extended lambda calculus.djvu/17



Now, What About Iteration?
Consider the "iterative" definition of. Although it appears to be recursive, since it "calls itself", we will see that it captures the essence of our intuitive notion of iteration.

Let us now compute.

Notice that the expressions involved have a fixed maximum size independent of the argument to ! In fact, as Marvin Minsky pointed out, successive reductions produce a cycle of expressions which are identical except for the numerical quantities involved. Looking back, we may note by way of comparison that the recursive version caused creation of expressions proportional in size to the argument. This is why we think that this version of  is iterative rather than recursive. At each stage of the iterative version the "state" of the computation is summarized in two variables, the counter and the answer accumulator, while at each stage of the recursive version the "state" contains a chain of pieces each of which contains a component of the state. In the recursive version of, for example, the state contains the sequence of multiplications to be performed upon return from the bottom. It is true that the iterative factorial also can produce expressions of arbitrary size, since