Thank you all for explaining this to me but I still don't understand
clojures behavior in this case,

Try running this code:

(def nums (drop 2 (range)))
(def primes (cons (first nums)
              (lazy-seq (->>
                (rest nums)
                (remove
                  (fn [x]
                    (let [dividors (take-while #(<= (* % %) x)
primes)]
                      (println (str "primes = " primes))
                      (some #(= 0 (rem x %)) dividors))))))))
(take 5 primes)

It prints out:
(primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
primes = (2)
2 3 5 7 9)

How can (println primes) ever print out (2) ? That means that primes
must have length 1 and that should be impossible no matter how chunked
it is. It's hard to believe that that is intended behavior.
I don't insist that a recursive lazy definition needs to work. It
could also throw an error. But simply giving incorrect and
unpredictable results can't be a good solution in my opinion.

-- 
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

Reply via email to