Clojure lazy sequences aren't required to be strictly lazy. Items can be computed in batches (chunks). It depends whether you source seq is chunked or not and whether your seq fns are chunk-aware or not.
#'range produces a chunked seq. See (chunked-seq? (seq (range 42))). That's most certainly why you observe this behaviour. hth, Christophe On Sat, May 21, 2011 at 6:43 AM, Jarl Haggerty <jarlhagge...@gmail.com>wrote: > I just remembered that people always ask me what version of clojure > I'm using, 1.3.0-master-SNAPSHOT. > > On May 20, 9:41 pm, Jarl Haggerty <jarlhagge...@gmail.com> wrote: > > I'm working on problem 66 at project euler and this is my solution so > > far. It calculates the minimum "x"s just fine but takes almost a > > minute when I turn limit up to 20. It's not going to solve the > > problem fast enough but what I find strange it that if I set the limit > > to 20 then nothing happens for a while and then the minimum "x"s are > > quickly spit out. Basically, it seems like the sequence in the loop > > isn't lazy and I don't understand why. > > > > Algorithm: For each D iterate over the squares. The minimum x will > > be the first square for which decrementing it and dividing by D is > > another square. > > > > (time (let [limit 10 > > sqrt (fn [n] (if (zero? n) > > 0 > > (loop [guess (- n (/ (- (* n n) n) (* 2 n))) > last-guess n] > > (if (< (- last-guess guess) 1/10) > > (let [dec-guess (long guess) > > inc-guess (inc dec-guess)] > > (condp = n > > (* dec-guess dec-guess) dec-guess > > (* inc-guess inc-guess) inc-guess > > guess)) > > (recur (- guess (/ (- (* guess guess) n) > (* 2 guess))) > > guess)))))] > > (loop [x (for [D (range (inc limit)) > > :when (not (integer? (sqrt D)))] > > (sqrt (first (filter (comp integer? #(sqrt (/ (dec %) > D))) > > (map #(* % %) (range 2 > Double/POSITIVE_INFINITY))))))] > > (when (first x) > > (println (first x)) > > (recur (rest x)))))) > > -- > 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 > -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.cgrand.net/ (en) -- 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