Blame


1 665c255d 2023-08-04 jrmu (define (new-if predicate then-clause else-clause)
2 665c255d 2023-08-04 jrmu (cond (predicate then-clause)
3 665c255d 2023-08-04 jrmu (else else-clause)))
4 665c255d 2023-08-04 jrmu (define (sqrt-iter guess x)
5 665c255d 2023-08-04 jrmu (new-if (good-enough? guess x)
6 665c255d 2023-08-04 jrmu guess
7 665c255d 2023-08-04 jrmu (sqrt-iter (improve guess x)
8 665c255d 2023-08-04 jrmu x)))
9 665c255d 2023-08-04 jrmu According to the general evaluation rule, all sub-expressions must be evaluated (the scheme interpreter follow applicative-order evaluation). The problem is that for sqrt-iter is that the 3rd expression that it passes to new-if is recursive. So, the interpreter will attempt to evaluate the 3rd sub-expression an never terminate. It ends up getting stuck in an infinite recursion. The reason the if-special form must be provided is so that the else-clause is never evaluated if the predicate evaluates to true. The "short-circuit"-ing behavior is necessary to avoid infinite recursion.