4.25 Exercise 4.25

Suppose we have the following procedure for computing factorials:

(define (factorial n)
  (unless (= n 1)
    (* n (factorial (- n 1)))
    1))

Ignoring the fact that this doesn’t compute the factorial of 0, this won’t work at all with strict evaluation. The arguments to the unless function will unconditionally be evaluated, meaning that the recursive call to factorial will always be evaluated and the procedure will never terminate. With lazy evaluation, we will only force the evaluation of the recursive call in the case where n is not equal to 1.