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



The semantics of this are that the variables are bound and initialized to the values of the  expressions, which must all be evaluated in the environment outside the  ; then the predicate   is evaluated in the new environment, and if , the   is evaluated and returned. Otherwise the body is evaluated, then each of the steppers  is evaluated in the current environment, all the variables made to have the results as their values, and the predicate evaluated again, and so on.

For example, the following MacLISP function:

computes the reverse of a list. In SCHEME, we could write the same function, in the same iterative style, as follows:

From this we can infer a general way to express iterations in SCHEME in a manner isomorphic to the MacLISP :

This is in fact what the supplied    expands into. Note that there are no side effects in the steppings of the iteration variables.

Another Way To Do Recursion
Now consider the following alternative definition of. It has an extra argument, the continuation [Reynolds], which is a function to call with the answer, when we have it, rather than return a value; that is, rather than ultimately reducing to the desired value, it reduces to a combination which is the application of the continuation to the desired value.