2009/3/3 Meikel Brandmeyer <m...@kotka.de>

> 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?


If you still want to force a veeerry long seq for side effect, without
fearing to face an OutOfMemory error ?


>
> 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
>
>

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to