What's the explanation for Exercise 1.6 in SICP?

前端 未结 6 637
一个人的身影
一个人的身影 2021-01-30 16:08

I\'m just beginning to work through SICP (on my own; this isn\'t for a class), and I\'ve been struggling with Exercise 1.6 for a couple of days and I just can\'t seem to figure

6条回答
  •  清歌不尽
    2021-01-30 16:16

    new-if is a procedure, and Scheme uses applicative-order evaluation (1.1.5), so even before new-if is actually performed, it has to evaluate all the arguments first, which are guess and (sqrt-iter (improve guess x) x). You can see that the latter argument is a recursion, which calls a new new-if procedure, this is how the infinite loop occurs.

    The ordinary if need not evaluate its arguments first, just go along the way, this is the difference between if and new-if. :)

提交回复
热议问题