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



Recursive programs
Now, let's see how lambda calculus may be used (informally) to model a computation. Consider the standard definition of the factorial function:

We are being very informal—lambda calculus as presented by [Church] does not include such constructs as,  , or  ,  , or even  ! The "usual" lambda calculus construct for defining recursive functions is a rather obscure object called the "fixed-point" operator. We have been lax to avoid the hassle of "rigor mortis" in this tutorial paper. Similarly,  is the SCHEME conditional construct we will use for convenience, it reduces to its second or third argument depending on whether the first reduces to   or. The objects,  ,  ,  , etc. may be thought of as abbreviations for complex lambda expressions (such as Church numerals) whose details we are not interested in. On the other hand, we may think of them as primitive expressions, defined by additional axioms; this viewpoint leads to practical interpreter implementations.

Now let's reduce the expression. We will perform the expression reductions, except for the  primitive, in Applicative Order (call by value), though this is not necessary, as we will discuss later. We display a "trace" of the substitutions:

You will note that we have calculated  by a process wherein each expression is replaced by an expression which is provably equivalent to it via an axiom or which is produced by application of a primitive function.