Hi,

Am 03.03.2009 um 16:42 schrieb Chouser:

If you have a lazy sequence with side-effects, you almost certainly
don't want to let it out of your sight.  You're likely to get very
strange behavior unless you're exceedingly careful.  Most likely, if
you've got a lazy seq with side effects you should force it with dorun
or doall immediately.  Use doall if you care about the values in the
produced seq, otherwise use dorun.

This means that dorun should almost always show up right next to the
form producing the lazy seq, which means doseq is very likely a better
choice, as it is more efficient and usually more succinct than dorun
combined with a lazy-seq producer.

What is the use case for dorun? It returns nil, so it can itself only
be called as a side-effect. From doall and dorun, only doall makes
sense to me. It is either called immediately

  (doall (map ...))

Or when giving the seq out of the hands:

  (with-some resource
    ...
    (doall the-seq))

Why should there ever be the need to call dorun?

And by the way: the output of the following code doesn't lie.

  (let [the-seq (map #(* % 2) (range 100))]
    (doseq [x the-seq]
      (println "Just produced:" x)))

'for' is in rather a different category, since unlike the others it
produces a lazy seq rather than forcing anything.  Use 'for' when it's
a more convenient way to express the lazy seq you want than the
equivalent combination of map, filter, take-while, etc.

I must confess, I almost never used for... Maybe I should
try to use it more often.

Sincerely
Meikel

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to