[racket] stream-cons from racket/stream isn't lazy
I see how this can make sense, however I'm not sure how to make it
work. For example:
> (define (foo) (display "called\n") empty-stream)
> (cons 1 (foo))
'(1 . #<promise:temp23>)
> (stream-cons 1 (foo))
called
#<sequence>
So stream-cons is strict even in lazy racket, perhaps because
stream-cons is defined in strict racket?
If I switch to lists, this works as expected:
> (define (make-lazy-list)
(define (next n) (cons n (next (+ n 1))))
(next 0))
> (display (take 5 (make-lazy-list)))
(0 1 2 3 4)
However using make-lazy-list from non-lazy racket gives an error:
> (display (take (make-lazy-list) 5))
take: index 5 too large for list (not a proper list): #<promise>
Which is kind of expected, since strict racket functions are not
prepared to deal with promises in arbitrary places.
Also, my original question is about streams in non-lazy racket.
Lazy/strict racket interaction is really a separate topic.
So is the current behaviour of stream-cons in racket considered
correct? What's the recommended way of getting lazy behaviour in
(non-lazy) racket?
Eugene
On Sat, Mar 5, 2011 at 5:20 PM, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
>
> On Mar 5, 2011, at 5:18 PM, Eugene Toder wrote:
>
>> I though that the whole point of streams was to provide lazy lists in
>> a strict language.
>
>
> I understand.
>
> I am interested in the following question: does it make sense to
> write parts of a systems in Lazy (so that you have lists=streams
> and you naturally stay in this world) and yet by linking to the
> strict world, you still get the best of both.
>
> -- Matthias
>
>