Am Mittwoch, 28. November 2012 16:42:32 UTC+1 schrieb Christophe Grand: > > Hi Ulrich, > > Wow, you got me scratching my head because your code should not even work. > The problem I see with it is that your recursion has no base case. You > have to know that 2 is prime to boot the algorithm. Eg > > ...
Salut Christophe, thanks first for pointing out to the clojure source for tracking down problems, I hadn't thought about that yet. Considering base case, in fact, the first code I started off with, was something similiar with starting values 2,3,5 : (def primes (concat '(2 3 5) (filter (fn[n] (every? #(pos? (mod n %)) (take-while #(<=(*%%)n) primes) ) ) (drop 6 (range)) ) ) ) What works. But with '(2,3) (or '(2) like you suggested) this doesn't work any more, as 25 is included in the first "batch" (of the so called chunked sequence) which is only tested against the starting value of primes. 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 :) Anyway, the question that still remains is, how one could "rechunk" a chunked sequence? Ulrich. > > -- 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