On Thu, Nov 19, 2009 at 05:51:22AM -0500, John Harrop wrote: >On Thu, Nov 19, 2009 at 4:31 AM, Lauri Pesonen <lauri.peso...@iki.fi> wrote: > >> (clojure.walk/macroexpand-all '(cond (even? 2) :foo (odd? 2) :bar :else >> :baz)) >> (if (even? 2) :foo (if (odd? 2) :bar (if :else :baz nil))) > >Eeeuw. Perhaps the cond macro should check if the last condition is >self-evaluating and, if it is, optimize appropriately?
Wouldn't it be better to do this kind of optimization in the compiler so that more than just cond benefits? I wonder how practical of an effect it has. The extra check does make the bytecode bigger, but the JIT might figure out the constant evaluation. The :else is evaluated at load time, not upon every evaluation, so it really is just adding a pointer compare and a branch to the code. David -- 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