Hi,
On Jul 21, 4:00 pm, ka <[email protected]> wrote:
> 1:13 user=> (def k (for [a (r 2 true)] a) )
> Called (r 2)
> #'user/k
>
> Why do you think for doesn't have 'lazy-for' semantics already?
Because then the above would look like:
user=> (def l (hypothetical-lazy-for [a (r 2 true)] a))
#'user/l
user=>
Compare:
user=> (def k (concat (r 2 true) (r 3 true)))
Called (r 2)
Called (r 3)
#'user/k
vs.
user=> (def k (lazy-cat (r 2 true) (r 3 true)))
#'user/k
> Also this thread has given me the insight that 'for' is not meant for
> Cartesian products of two seqs (contrary to what I thought) -
You are right in so far as for is not meant for cartesian products
exclusively. But a cartesian product is one case, which can be covered
by for. But for is much more general than that.
Try this:
user=> (let [rs2 (r 2 true)
rs3 (r 3 true)]
(for [r2 rs2
r3 rs3]
[r2 r3]))
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])
If your input sequences are independent of each other, and they come
from a (possibly expensive) function call, use let in the above
fashion.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en