To the best of my knowledge the only guarantee you get is the *existence* of 
an upper bound on the size of the eagerly fetched chunk, so a potentially 
infinite lazy sequence will not result in an endless loop/OOME. The whole 
mechanism is based on a best-effort policy.

On Friday, March 15, 2013 2:08:58 AM UTC+1, Paul Butcher wrote:
>
> Clojure's sequences are lazy - but is there anything that guarantees *how* 
> lazy they are?
>
> To give a concrete example - given an infinite lazy sequence of promises:
>
> (def promises (repeatedly promise))
>
> If, in one thread I do:
>
> (doseq [p (map deref promises)] (println p))
>
> And in another thread, I call deliver on various elements of promises, 
> will promises always be printed as soon as they're available? Or can things 
> block for longer than they theoretically might because a later 
> (undelivered) promise in the sequence is being realized?
>
> I've been doing some experiments, and in practice the above works just 
> fine - promises are printed as soon as they theoretically might be. If, 
> however, I put a "flatten" in place of the map then I seem to have to 
> deliver one more promise before the first is printed.
>
> What I'm interested in here aren't practicalities. I'm interested in what 
> Clojure and its libraries guarantee (if anything) about laziness. Is there 
> an upper bound on how much of a sequence will be realized?
>

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to