Hello, I am very new to Clojure, so please bear with me. I was reading "Programming Clojure" and while reading about Macros, (specifically Symbol Capture) I had the following question, could it be possible to expand the macro into an anonymous function and evaluate that? For example:
(defmacro bench [expr] `(let [start# (System/nanoTime) result# ~expr] {:result result# :elapsed (- (System/nanoTime) start#)})) would be expanded as : (macroexpand-1 '(bench f)) (clojure.core/let [start__154__auto__ (System/nanoTime) result__155__auto__ f] {:result result__155__auto__, :elapsed (clojure.core/- (System/nanoTime) start__154__auto__)}) instead, couldn't it be expanded to ((fn[f] (clojure.core/let [start (System/nanoTime) result f] {:result result, :elapsed (clojure.core/- (System/nanoTime) start)})) f) My thinking is that the anonymous function would protect the scope of the let bindings inside of it which will make something like : (let [start 0] (bench f)) run correctly without capturing the start from the higher let binding. I would like to know if this would work, and if not, why. The only thing I can see this helping with is removing the need for "result#" syntax, and the compiler keeping track of unique symbols in the same scope Thanks, -Kenan -- 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