Considering for the sake of argument the possibility that it is a 
legitimate bug, and not a result of misusing the language features, it is a 
family of bug that will be more common than most, because it reflects a 
style of programming that is rare in real Clojure code.

But it isn't a bug.

Lazy-seqs don't promise to be "as lazy as possible", and when we step 
through the logic of the original code in Michael Blume's post, we can see 
why chunking breaks it. Taking for granted that something lazy is realized 
with a specific granularity is an error in Clojure (see also lazy-seqs used 
inside with-open blocks or db transactions - the opposite error is common, 
not being strict enough).

defn primes [] (let [primes' (atom nil)]
                 (reset! primes' (cons 2 (filter #(prime? @primes' %) (drop 
3 (range)))))))

The first time through the above code, primes' will be empty, so the first 
chunk of results will all be calculated with an empty list of candidate 
divisors.

On Thursday, February 12, 2015 at 5:26:52 PM UTC-8, Jorge Marques Pelizzoni 
wrote:
>
>
> Beautiful, Armando! Thanks for your the insight. Anyway, I really don't 
> buy the "that's the way it is" argument. Totally looks like a bug and I 
> don't find it a coincidence it is working differently in the development 
> branch. Thank you all for your time :)
>
> Em quinta-feira, 12 de fevereiro de 2015 22:30:02 UTC-2, Armando Blancas 
> escreveu:
>>
>> Jorge, I tried this on 1.6 and seemed to work:
>>
>> (def primes
>>   (cons 2 (for [n (iterate inc 3) :when (prime? primes n)] n)))
>>
>>
>>

-- 
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/d/optout.

Reply via email to