Exercise 1.5

How will the evaluation of the following procedures differ under applicative-order evaluation and normal-order evaluation?

(define (p) (p))

(define (test x y)
  (if (= x 0)
      0
      y))

(test 0 (p))

Under applicative order, the test procedure will fail, because the interpreter will attempt to resolve the argument (p), which is circular, before applying the procedure. Under normal order, (p) would never be evaluated, because the interpreter will first expand the definitions and only evaluate arguments when needed:

(test 0 (p))
(if (= 0 0) 0 (p))
(if #t 0 (p))
0

Back to exercises