>
> Is there a philosophical difference underlying the syntax difference
> (doseq [elem coll] (f coll)) and (each f coll)?
>

`doseq' is the side-effecty version of `'for', not map. It lets you do
things like

user> (doseq [x (range 100)
              :while (< x 20)
              :when (even? x)]
         (println x))
0
2
4
6
8
10
12
14
16
18

If you want a side-effecty version of map, I would avoid the macro
suggested earlier, and just do

(def each (comp dorun map))

or

(defn each [f coll] (doseq [x coll] (f x)))

-Walter

On Sat, Jun 9, 2012 at 5:08 PM, David Jacobs <da...@wit.io> wrote:

> 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

Reply via email to