Exercise 1.6 defines a new-if
with cond
:
(define (new-if predicate then-clause else-clause)
(cond (predicate then-clause)
(else else-clause)))
This new-if
would fall into infinite loop when called in a recursion.
Example sqrt-iter
illustrates the fact that arguments are evaluated immediately after passing into a user-defined
function.
The (infinite)stream
introduced in 3.5 is also defined a function:
(define (cons-stream a b)
(cons a
(delay b)))
The key point to build it, according to the text book, is delay
.
But supposed you build a stream:
(define (intgers-starting-from n)
(cons-stream n
(intgers-starting-from (+ n 1))))
(define integers (intgers-starting-from 1))
Using the same evaluator as it in new-if
, you won't get it working because (intgers-starting-from n)
would always evaluate (intgers-starting-from (+ n 1))
and obviously there is no end to it despite how delay
is implemented.
Is it contradictory that SICP assumes such evaluator that works for cons-stream
but not for new-if
?