I've got a utility function I've been using called `conditionally-transform` which is a non-macro version of `test->`. I think both cond-> and if-> have a similar problem in that, if you already understand if/cond/-> then it gives you little insight into how the new threading macro works.
Both these names focus on the conditional nature of the macro. Perhaps a name based on the transformative nature of the macro: trans-> or transform-> ? These convey the idea of threading through various transformations. For when->, how about non-nil-> ? I'd feel better about some-> if it came, as you said, with other new functions that use the syllable 'some', thus expanding the Clojure lexicon. As it stands I don't feel like some-> has a particularly intuitive meaning. Alex On Fri, Nov 30, 2012 at 9:33 AM, Jay Fields <j...@jayfields.com> wrote: > On Fri, Nov 30, 2012 at 10:37 AM, Rich Hickey <richhic...@gmail.com> > wrote: > > The new names being considered for let->, test-> and when-> are: > > > > A) let-> becomes as-> > > I prefer ->as, but don't feel strongly about it. > > (-> 1 > str > (->as one-str > (count one-str) > (* 2 one-str))) ;; returns 2 > > The thing that I like about this is that it reads to me as "thread > as", and the ordering of "->" and "as" reminds me that the args are > slightly different from traditional threading macros (i.e. it's not > (thread-macro x & forms). > > > B) test-> becomes cond-> > > I don't like cond-> for the same reason I didn't like let->, the > cond-> isn't easy to understand if you already understand cond and ->. > To try to come up with a name that I like, I tried to write some > similar code to see what I would use. I came up with the following: > > (->> 1 > (#(if (number? %) (str %) %)) > (#(if (string? %) (count %) %))) ;; returns 1 > > Which led me to the following (the best I can come up with right now). > > (if-> 1 > number? str > string? count) ;; returns 1 > > I don't think this is a homerun, as the understanding of "if" and "->" > wouldn't guarantee an understanding of this. However, I couldn't come > up with an example of solving a similar problem with -> and cond in > any sensible way. I don't think the shape of the arguments should > define the name, which is the only reason you'd want to use "cond", > imho. > > I also considered something that expressed "if or identity. Perhaps > something like the following > > (ifoi-> 1 > number? str > string? count) ;; ifoi stands for "if or identity". > > You could also use ifei->, for "if else identity" > > Perhaps the issue is resolved if the form can take an else fn. Then > the original if-> example becomes > > (if-> 1 > number? str identity > string? count identity) > > This also gives you the freedom to put any function you want in the > else clause. I don't know if that's a good thing or not. > > Or, since the significant majority of us have auto-complete, perhaps > the following works > > (if-else-identity-> 1 > number? str > string? count) > > > C) when-> becomes some-> > > I don't see any issue with when->, that one actually seems very clear. > Is the issue that you want to be able to continue the threading with > false? If so, I wouldn't overload the meaning of "some", I'd simply > make it take a test fn - then you can use any pred you want. > > (->when (comp not nil) (f1) (f2)) > > Which is even more clear if you define not-nil? in core. Then all of > the following would easily work > > (->when 1 not-nil? (f1) (f2)) ; thread when not nil > (->when 1 identity (f1) (f2)) ; thread when truthy > (->when 1 #{1 2 3} (f1) (f2)) ; thread when the value is 1 2 or 3. > > note, I switched the order again, as I like the way it reads (e.g. > "thread when 1 is not nil"), and it reminds me that this is a > threading macro that takes more than x & forms. > > -- > 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