Kevin Kleinfelter <kleinfelter.gro...@gmail.com> writes:

> I'm stumped by the behavior of the following code fragment.  Can someone 
> help me understand what's happening?
>
> *This code*:
>   (println "Holding:" (:class holding))
>   (let [t (:class holding)]
>       (for [x t] (println "here" x))
>       (for [x t] (println "there" x))))
>
> *Produces this output*:
> holding: {:fundname Mutual Fund 1, :value 123.45, :class [{:class sell-me, 
> :percent 100}]}
> class: [{:class sell-me, :percent 100}]
> Holding: [{:class sell-me, :percent 100}]
> there {:class sell-me, :percent 100}
>
> Why doesn't the 'for' with "here" print anything?

'for' is lazy. the result isn't realized anywhere. the second 'for' is
realized because you print the result in the REPL (at least that is what
I assume).

try (doseq [x t] ...)

-- 
Cheers,
Ralf

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to