Hi, Beware the personal opinion!
map applies a function to each element of a sequence and returns a sequence of the results. If you call the "function" just for side-effects, but not the return value, then the semantics of map don't apply. Kind regards Meikel -----Ursprüngliche Nachricht----- Von: David Jacobs <da...@wit.io> An: clojure@googlegroups.com Gesendet: Sa, 09 Jun 2012, 23:08:21 MESZ Betreff: Re: Doseq, map-style Thanks, guys. I know there are easy ways to implement what I want. However, I'm more curious as to why the language itself doesn't support this style of mapping side-effects. In other words, why does doseq not follow map's lead here. Is there a philosophical difference underlying the syntax difference (doseq [elem coll] (f coll)) and (each f coll)? It seems to me that the side-effecty nature of (doseq) isn't quite enough to justify the syntax difference between map and doseq. I guess one could say that because doseq is built for side-effects, which are often multiline, doseq should easily accept multiline statements. However, my imaginary each macro could do the same: (each #(do … …) coll). What am I missing? Thanks! David On Friday, June 8, 2012 at 7:00 AM, Lars Nilsson wrote: > On Fri, Jun 8, 2012 at 9:54 AM, Allen Johnson <akjohnso...@gmail.com > (mailto:akjohnso...@gmail.com)> wrote: > > Combine map with dorun and you get the same effect: > > > > (dorun (map println logs)) > > > > http://clojure.github.com/clojure/clojure.core-api.html#clojure.core/dorun > > > > Allen > > > > On Thu, Jun 7, 2012 at 11:32 PM, David Jacobs <da...@wit.io > > (mailto:da...@wit.io)> wrote: > > > I would love to have a version of doseq that works like map (similar to > > > "each" in other dynamic languages). In other words, instead of (doseq [log > > > logs] (println log)), I would say something like (each println logs). > > > > > > Is there a built-in Clojure method that works like this? > > Not a built-in, but... > > (defmacro for-each [f x] `(doseq [item# ~x] (~f item#))) > > I suppose this solution is blindingly obvious though. > > Also, I would be curious if there's any significant performance > difference using (dorun (map ...)) as I assume an intermediate result > is built and then thrown away. Or perhaps it's insignificant compared > to what the unspecified function does that is passed to map for > performing the side-effect work.. > > Lars Nilsson > > -- > 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 > (mailto: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 > (mailto: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 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 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