In addition to question What's the explanation for Exercise 1.6 in SICP?. So Dr. Racket (R5RS) evaluates sqrt-iter function with "if" in finite time, clearly showing normal order evaluation. But if I use example from exercise 1.5
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
(test 0 (p))
it goes into infinite loop, making me think "if" uses applicative order evaluation. So where am I wrong?
What happens is that the if
is never reached: precisely because of the applicative order of evaluation both arguments to test
get evaluated before actually calling test
, and the expression (p)
will loop forever.
If the same procedure were evaluated using normal order it would return zero, that's what this example is trying to demonstrate in the first place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With