Exercise 4.25. Suppose that (in ordinary applicative-order Scheme) we define unless as shown above and then define factorial in terms of unless as
(define (factorial n)
(unless (= n 1)
(* n (factorial (- n 1)))
1))
What happens if we attempt to evaluate (factorial 5)? Will our definitions work in a normal-order language?
对 applicative-order,unless 如果被定义成了过程,则参数会全部计算完成之后才被传到过程体里面。所以
(* n (factorial (- n 1)))
会不断地求值,得到死循环(无限递归)。
而作为 normal-order,unless 就相当于 if 语句。每一次调用 unless 都相当于 if 语句先判断 (= n 1),所以在 normal-order 中,这个 factorial 过程是可以得到结果的。