On Wednesday, November 26, 2014 10:06:41 PM UTC-5, Michael Blume wrote: > > Instead of the deshadowing logic, why not > > (defn if-and-let* > [bindings then-clause else-fn-name] > (if (empty? bindings) > then-clause > `(if-let ~(vec (take 2 bindings)) > ~(if-and-let* (drop 2 bindings) then-clause else-fn-name) > (~else-fn-name)))) > > (defmacro if-and-let > [bindings then-clause else-clause] > (let [efname (gensym)] > `(let [~efname (fn [] ~else-clause)] > ~(if-and-let* bindings then-clause efname)))) >
That ought to work too, but in a way it does the same basic thing, just relying on fn to capture the lexical bindings in effect. I think it might have more overhead, though, including that it constructs an object at runtime for the else clause closure which may or may not even be needed. I'm not sure what the overhead of a bunch of lets is, or of no-op pairs of let such as (let [x y] ... (let [y x] ... y)), though. Perhaps someone can run speed tests of both versions under various circumstances, see which one the runtime/JIT does a better job of optimizing. -- 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/d/optout.