[plt-scheme] stream-delay question
In srfi-40, stream-delay is just the compose of delay and force.
To understand why stream-delay is needed, "from0" is not a good example.
Let's consider another example. Suppose you stream should be:
(if (some-complex-condition)
(stream-cons x y)
(stream-cons u v))
(where the the value of x y u v might be bound when doing
"some-complex-condition")
Then the difference shows up. If you say
(define my-stream
(stream-delay
(if (some-complex-condition)
(stream-cons x y)
(stream-cons u v))))
everything is fine. But if you omit the stream-delay, the
"some-complex-condition" will be evaluated immediately, which is not
what we went when define a stream.
Chongkai
Robert Nikander wrote:
> Hi,
>
> I'm trying to learn srfi-40 (streams), and I don't understand
> stream-delay. The srfi doc uses it in an example stream `from0'. Can
> someone give me an example where from0 and from0/no-delay behave
> differently?
>
>
> (require (lib "40.ss" "srfi"))
>
> (define from0
> (let loop ((x 0))
> (stream-delay
> (stream-cons x (loop (+ x 1))))))
>
> (define from0/no-delay
> (let loop ((x 0))
> (stream-cons x (loop (+ x 1)))))
>
>
> thanks,
>
> Rob
>
>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme