]> git.rkrishnan.org Git - sicp.git/blob - src/sicp/ex1_5.clj
Merge branch 'master' of github.com:vu3rdd/sicp
[sicp.git] / src / sicp / ex1_5.clj
1 (ns sicp.ex1_5
2   (:use [sicp utils]
3         [clojure.contrib trace test-is]))
4
5 ;; exercise 1.5:  Ben Bitdiddle has invented a test to determine
6 ;;                whether the interpreter he is faced with is
7 ;;                using applicative-order evaluation or normal-order
8 ;;                evaluation. He defines the following two procedures:
9 ;; (defn p [] (p))
10 ;; (defn test [x y]
11 ;;   (if (= x 0)
12 ;;    0
13 ;;    y))
14 ;;
15 ;; Then he evaluates the expression
16 ;;
17 ;; (test 0 (p))
18 ;;
19 ;; What behavior will Ben observe with an interpreter that uses
20 ;; applicative-order evaluation?
21 (comment
22   In the case of applicative order evaluation, the test gets into
23   and infinite loop (eventually using all the stack), as the parameters
24   are evaluated before they are actualy used in the function.
25   )
26 ;; What behavior will he observe with an interpreter that uses
27 ;; normal-order evaluation? Explain your answer.
28 (comment
29   It will print 0, as (p) is not evaluated in this case.
30   )