Skip to content

Instantly share code, notes, and snippets.

@kEND
Forked from jimweirich/gist:189248
Created September 20, 2009 02:04
Show Gist options
  • Save kEND/189673 to your computer and use it in GitHub Desktop.
Save kEND/189673 to your computer and use it in GitHub Desktop.
Exercise 1.5
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
applicative-order evaluation
evaluate arguments and then apply
normal-order evaluation
fully expand and then reduce
(test 0 (p))
(if (= x 0) 0 y)
(if (= 0 0) 0 (p))
* To apply a compound procedure to arguments, evaluate the body of the procedure with each formal parameter replaced by the corresponding argument.
I am having difficulty understanding how to evaluate (p). However, under normal-order evaluation, it would be evaluated last (during the reduction). With applicative-order evaluation, (p) would be evaluate first and applied to (test 0 results-of-(p)). So (p) evaluates to (p) which evaluates to (p)... infinite loop under applicative-order evaluation. Under normal-order evaluation, the 0 = 0 condition would be met and (p) would not be evaluated therefore no infinite loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment