On Wed, Nov 28, 2012 at 5:24 PM, Ulrich <umuel...@c007.de> wrote: > Then I found the solution with "iterate" and then further reduced starting > values to '(2) and then to '() what worked as well, > as every? returns true for empty sequences, what is right from a logical > point of view too. And with '() as start even the concat wasn't necessary > any more. So this was no luck, but intention :) >
It was your intention then but based on a false premise: a seq is immutable and as such can't be both empty and non-empty depending how/when you access it. There is no fix-point semantics to justify this behaviour. So to me it's a bug. With '(2 3 5) it worked because it was enough to remove all non primes from the first chunk (< 32). With the patch I propose I get: * without a base case for recursion, I get an exception, chunked or not. user=> (def primes (filter (fn isprime[n] (every? #(pos? (mod n %)) (take-while #(<=(* % %)n) primes))) (drop 2 (range)))) #'user/primes user=> (take 50 primes) RuntimeException Recursive seq realization clojure.lang.LazySeq.sval (LazySeq.java:64) user=> (def primes (filter (fn isprime[n] (every? #(pos? (mod n %)) (take-while #(<=(* % %)n) primes))) (iterate inc 2))) #'user/primes user=> (take 50 primes) RuntimeException Recursive seq realization clojure.lang.LazySeq.sval (LazySeq.java:64) * With a base case however I get either the right result or an exception. Even if the chunkiness of the seq still changes the outcome, it's an improvement over the current situation where one gets either the right result or an incorrect result. Better to fail than to err. user=> (def primes (cons 2 (filter (fn isprime[n] (every? #(pos? (mod n %)) (take-while #(<=(* % %)n) primes))) (iterate inc 3)))) user=> (take 50 primes) (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229) user=> (def primes (cons 2 (filter (fn isprime[n] (every? #(pos? (mod n %)) (take-while #(<=(* % %)n) primes))) (drop 3 (range))))) #'user/primes user=> (take 50 primes) RuntimeException Recursive seq realization clojure.lang.LazySeq.sval (LazySeq.java:64) On Thu, Nov 29, 2012 at 1:11 AM, Ulrich <umuel...@c007.de> wrote: > Has the afore mentioned interface for forced single-item consumption > meanwhile been created? Afaik, no. Christophe -- On Clojure http://clj-me.cgrand.net/ Clojure Programming http://clojurebook.com Training, Consulting & Contracting http://lambdanext.eu/ -- 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