Since a few of these higher order functions--map, filter, reduce, etc.--are so common and useful, I wonder whether there could be sufficient benefit to having some abbreviations for them. I know that some of these characters are already taken, but just to sketch the idea:
(--> things %wrangle %pacify |effable %#(aggravate % :bees :sharks) \(mapinate {}) ) In one sense this reduces the visual complexity of Korny's example. In another sense it increases it. I thought this option was worth mentioning, but I don't think I like it. It makes the syntax closer to line noise, and if there are too many magical characters, no one will remember what they mean except the people who use them all of the time (like some of the options in Perl regexps). Why not go all the way, and provide an alternate APL-style syntax <http://c2.com/cgi/wiki?AplLanguage> for Clojure? On Friday, February 7, 2014 9:14:27 AM UTC-6, t x wrote: > > I think > > (->> things > (map wrangle) > (map pacify) > (filter effable) > (map #(aggravate % :bees :sharks)) > (reduce mapinate {}) > > > is optimal for the following reason: > > > If you're doing "map" and "map alone", i.e. > > (->> things > (map f1) > (map f2) > (map f3) > (map f4)) > > then you can do: > > (map #(f4 (f3 (f2 (f1 %)))) things) > > > Now, if you're not doing pure maps, i.e. maps + filters > > Then for each function call, from an information theoretic > perspective, you have to, at the very least, specify: > > (*) the function to be called > (*) whether it's a filter or a map > > in this case, > > what you initially have is optimal. > > On Fri, Feb 7, 2014 at 6:33 AM, Korny Sietsma > <ko...@sietsma.com<javascript:>> > wrote: > > I tend to agree, I think. I certainly can't think of a syntax that > would > > make me happy. It just feels like a bit of a smell that I keep using > ->> to > > process sequences in similar ways. > > > > The data.zip "xml->" macro is an example of something like what I'm > thinking > > about - it lets you process sequences of xml data nicely: > > http://clojure.github.io/data.zip/#clojure.data.zip.xml/xml-> > > > > ... but I can't see a way to use something similar for the sort of data > I'm > > processing. I'll let this percolate, and stick to just using lots of > (map) > > and (filter) instead. > > > > - Korny > > > > > > On 6 February 2014 18:34, Jozef Wagner <jozef....@gmail.com<javascript:>> > wrote: > >> > >> I agree with Colin, the cognitive load is greater than benefits of such > >> approach. BTW you can use comp to chain consecutive map transformation > >> functions. (map (comp pacify wrangle) things) > >> > >> JW > >> > >> > >> On Thu, Feb 6, 2014 at 3:40 PM, Korny Sietsma > >> <ko...@sietsma.com<javascript:>> > wrote: > >>> > >>> Hi folks, > >>> > >>> I seem to regularly find myself writing ->> threaded code that follows > >>> similar patterns: > >>> > >>> (->> things > >>> (map wrangle) > >>> (map pacify) > >>> (filter effable) > >>> (map #(aggravate % :bees :sharks)) > >>> (reduce mapinate {}) > >>> > >>> i.e. all stages of the code actually operate on a collection rather > than > >>> a single value - usually with a call to "map" at each stage. This > example > >>> is over simplified - often many of the calls to map are inline > functions, > >>> which makes this even more verbose. > >>> > >>> I wonder if there would be value in (yet another) variant on '->' that > >>> assumes you are threading a collection and calling 'map' by default. > I'm > >>> not sure of the syntax that would work though. Something like: > >>> > >>> ([]-> things > >>> wrangle > >>> pacify > >>> [:filter effable] > >>> (aggravate :bees :sharks) > >>> [:reduce mapinate {}]) > >>> > >>> I'm not sure about the syntax for non-map functions, I'm not even sure > if > >>> this is worthwhile. Thoughts? > >>> > >>> - Korny > >>> > >>> -- > >>> Kornelis Sietsma korny at my surname dot com http://korny.info > >>> .fnord { display: none !important; } > >>> > >>> -- > >>> 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<javascript:> > >>> 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 <javascript:> > >>> 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 <javascript:>. > >>> 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 clo...@googlegroups.com<javascript:> > >> 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 <javascript:> > >> 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 <javascript:>. > >> For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > > > > -- > > Kornelis Sietsma korny at my surname dot com http://korny.info > > .fnord { display: none !important; } > > > > -- > > 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<javascript:> > > 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 <javascript:> > > 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 <javascript:>. > > 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.