I'm not really talking about semantics here, I'm saying that the semantic 
difference between the two methods (map and my hypothetical each) probably 
don't need to be reflected in the language syntax. To me, it feels weird 
that doseq *doesn't actually call the function you pass in for you*. 
Instead, you have to call it yourself on an item from the list that you 
*also locally bound yourself*.

On Sunday, June 10, 2012 12:46:27 AM UTC-7, Meikel Brandmeyer (kotarak) 
wrote:
>
> 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 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 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
>
>
On Sunday, June 10, 2012 12:46:27 AM UTC-7, Meikel Brandmeyer (kotarak) 
wrote:
>
> 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 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 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