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