-
-
Save kEND/189673 to your computer and use it in GitHub Desktop.
Exercise 1.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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