Details

Type: Defect

Status: Reopened

Priority: Major

Resolution: Unresolved

Affects Version/s: None

Fix Version/s: None

Component/s: None

Labels:None

Patch:Code and Test
Description
If you define a global data var in terms of a lazy sequence referring to that same var, you can get different results depending on the chunkiness of laziness of the functions being used to build the collection.
Clojure's lazy sequences don't promise to support this, but they shouldn't return wrong answers. In the example given in http://groups.google.com/group/clojure/browse_thread/thread/1c342fad8461602d (and repeated below), Clojure should not return bad data. An error message would be good, and even an infinite loop would be more reasonable than the current behavior.
(Similar issue reported here: https://groups.google.com/d/topic/clojure/yD941fIxhyE/discussion)
(def nums (drop 2 (range Long/MAX_VALUE))) (def primes (cons (first nums) (lazyseq (>> (rest nums) (remove (fn [x] (let [dividors (takewhile #(<= (* % %) 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)
Converted from http://www.assembla.com/spaces/clojure/tickets/457