On Jul 27, 8:56 pm, Dmitry Gutov <raa...@gmail.com> wrote: > > First: Why doesn't macroexpand expand the inner when-lets? > > It's not supposed to, see the doc. To do full expansion, you can use > `clojure.walk/macroexpand-all`.
Oh, yeah. Thanks! > > Is the gensym in the two expands the same thing, or do "they" get the > > same name? That was surprising to me. I can't think of any real > > example where that is a problem. But what if I had wanted to write a > > macro like the second when-lets? > > Looks like a bug/limitation of the gensym reader macro, these symbols > are treated as belonging to the same quoted form, so they get the same > name. > But I don't think the second macro does what you're saying - the > evaluation order is the same Yes of course. I was tired yesterday. :) > , since `tst` is evaluated in the `let` > form above `when-lets` in both cases, only the order of binding the > values is reversed. > To reverse the evaluation order, you need to move that `let` inside: > > (defmacro when-lets > [bindings & body] > (if-not (seq bindings) > `(do ~@body) > (let [form (bindings 0) tst (bindings 1) rst (drop 2 bindings)] > `(when-lets ~(vec rst) > (let [temp# ~tst] > (when temp# > (let [~form temp#] > ~@body))))))) > > user=> (when-lets [b (inc a) a 3] (+ b a)) > 7 -- 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