The trick lies in how we implement cons-stream
. You explicitly created an evaluation promise when you defined the (lambda () ...)
thunk. The special form cons-stream
does this, but implicitly and using Scheme's primitives. For example, it can be implemented like this, notice how we use delay
:
(define-syntax stream-cons
(syntax-rules ()
((stream-cons head tail)
(cons head (delay tail)))))
It makes more sense to encapsulate all the promise-creation logic in a single place, say cons-stream
, instead of explicitly creating thunks everywhere.