In order to implement stream_conswe require two other primitives delay and force.
does not evaluate
but delays the evaluation. force takes a delayed object and evaluates it. Using these two
primitives we can define
and the associated
and
functions.
stream_cons(a, b) = cons(a, delay(b)) hd(s) = car(s) tl(s) = force(cdr(s))
Note that delay can be easily implemented by wrapping a
around the term being delayed. force just uses apply on the delayed object.
delay(b) = )
force(e) = e()
Here stands for unit.