@Meikal, Hi, I get what you mean. Consider the following func -
(defn r [n lazy?] (.println System/out (str "Called (r " n ")")) (let [r-lazy-seq (fn r-lazy-seq [i n] (lazy-seq (when (< i n) (.println System/out (str "Realizing elem " i)) (cons :a (r-lazy-seq (inc i) n))))) zzz (r-lazy-seq 0 n)] (if lazy? zzz (doall zzz)))) 1:13 user=> (def k (for [a (r 2 true)] a) ) Called (r 2) #'user/k 1:14 user=> (def k (for [a (r 2 false)] a) ) Called (r 2) Realizing elem 0 Realizing elem 1 #'user/k Why do you think for doesn't have 'lazy-for' semantics already? Also this thread has given me the insight that 'for' is not meant for Cartesian products of two seqs (contrary to what I thought) - 1:40 user=> (use '[clojure.contrib.combinatorics]) nil 1:41 user=> (cartesian-product (r 2 true) (r 3 true)) Called (r 2) Called (r 3) Realizing elem 0 Realizing elem 0 Realizing elem 1 Realizing elem 2 Realizing elem 1 ((:a :a) (:a :a) (:a :a) (:a :a) (:a :a) (:a :a)) 1:42 user=> (for [a (r 2 true) b (r 3 true)] [a b]) Called (r 2) Realizing elem 0 Called (r 3) Realizing elem 0 Realizing elem 1 Realizing elem 2 Realizing elem 1 Called (r 3) Realizing elem 0 Realizing elem 1 Realizing elem 2 ([:a :a] [:a :a] [:a :a] [:a :a] [:a :a] [:a :a]) - Thanks -- 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