1.5

Application order:

(test 0 (p))

(test 0 (p))

(test 0 (p))

...

 

Normal order:

(test 0 (p))
(
if (= 0 0)
0
(p)))

0

 

1.6 

new-if will cause the infinite loop:

(sqrt-iter 1.0 9)

(new-if
(good-enough? 1.0 9)
     9
     (sqrt-iter (improve 1.0 9) 9))

(new-if #f
     9
     (sqrt-iter 5.0 9))

(new-if #f
     9
     (new-if (good-enough? 5.0 9)
          9
          (sqrt-iter (improve 5.0 9) 9))
...

 

Since scheme is application-order, it will evaluate the subexpression at the beginning of the invocation. new-if function will evaluation the else-clause which is (sqrt-iter (improve 1.0 9) 9), but the sqrt-iter function will invoke new-if function again. 

 

posted on 2010-07-02 19:54  Leonard  阅读(165)  评论(0)    收藏  举报