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
There are three ways a form may be evaluated in Scheme:
f(x)=x+x: 3*f(1)*f(1) ⇒ 3*2*2f(x)=x+x: 3*f(1)*f(1) ⇒ 3*(1+1)*(1+1) (also used in "lazy evaluation")and and or. For example: (and ... ) evaluates Left → Right. If any evaluates to false, the value of the and expression is false, and the rest of the 's are not evaluated.if and cond
(if ) : If the evaluates to a true value, the interpreter then evaluates the and returns its value. Otherwise it evaluates the and returns its value(cond ( ) ... ( )) : The predicate is evaluated first. If its value is false, then is evaluated. If 's value is also false, then is evaluated. When true predicate, the interpreter returns the value of the corresponding consequent expression .In the case of Exercise 1.6:
new-if is a normal procedure. In Scheme (and many other languages), arguments are fully evaluated before the procedure is called. This is known as applicative order. ∴ sqrt-iter is called every time new-if is called, resulting in an infinite loop.ifs are a special form. The recursive statement wouldn't be evaluated unless the is called.