Oh happy day! :-D Today I was looking at some clojure code on using core.async with ClojureScript [1], and the example used this strange "as->" expression that I'd never seen before (I'm from the 1.2 era, just getting back into the Clojure game), and I was trying to figure out what the heck this thing was.
There are no examples on clojuredocs.org, and without an example I couldn't be sure whether my interpretation of (doc as->) was correct. All attempts to search the web for "as->" failed miserably because search engines don't care for special characters, so I searched the list and found this thread. It turns out my wish for a generalized threading macro three years ago came true!! https://groups.google.com/forum/#!msg/clojure/6Cb8MD5EC3w/y1mNNK3ZUxYJ Thank you Rich (or whoever's responsible)!!! :-D Cheers, Greg [1] http://swannodette.github.io/2013/07/12/communicating-sequential-processes/ -- Please do not email me anything that you are not comfortable also sharing with the NSA. On Feb 18, 2013, at 3:33 PM, VĂctor M. V. <v...@vemv.net> wrote: > Fair enough. Now I'm beggining to truly appreciate as->, thank you. I still > believe as->> would be somewhat useful but I don't see it getting added to > clojure.core now. > > On Mon, Feb 18, 2013 at 9:10 PM, Marko Topolnik <marko.topol...@gmail.com> > wrote: > as-> is meant to be used as the only threading form. In your example you'd > want to replace the initial ->> with as->. > > > On Monday, February 18, 2013 9:04:55 PM UTC+1, vemv wrote: > That extra parenses trick is neat, never thought of that! > > As for as->> being redundant - it could be considered so indeed, given that > as-> can be lambified: (->> [] (#(as-> % x (map inc x)))) - but that's pretty > damn ugly haha. If you were thinking something else, please let me know. > > Thanks - Victor > > On Mon, Feb 18, 2013 at 8:44 PM, Marko Topolnik <marko.t...@gmail.com> wrote: > On Monday, February 18, 2013 5:40:51 PM UTC+1, vemv wrote: > > And neither can be solved by adding a lambda: > > (-> [[1 1 1] 2 3] (nth 0) #(map inc %)) ;; fail > > Lambda does solve it, you are just missing the parens around the lambda: > > (-> [[1 1 1] 2 3] (nth 0) (#(map inc %))) > > > > Clojure 1.5's as->, though, can come to the rescue. > > (-> [[1 1 1] 2 3] (nth 0) (as-> x (map inc x))) ;; cool > > Now, I only wish 1.5 came with as->> macro! Its implemetation is trivial > anyway. > > (->> [1 2 3] (as->> _ (nth _ 0))) > > Of course, for the given examples, using these "as" forms is overkill. But if > you've ever ended up writing large expressions (especially when > experimenting) which arbitrarily nest/interleave ->> and ->, using as-> and > as->> can provide a more sequential, structured alternative. > > Couldn't find any related discussion about the uses of as->, as its name is > unfriendly to Google/JIRA searches. Thoughts? > > as-> is actually a generalization of both -> and ->>: you get to choose where > to involve the previous result in each form. That is why as->> would be > redundant. > > -Marko > > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+u...@googlegroups.com. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > > > -- > -- > 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 unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > -- -- 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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.