On Nov 26, 12:25 am, Sunil S Nandihalli <sunil.nandiha...@gmail.com> wrote: > I just realized that we don't need to use the with-symbol-macros when using > symbol-macrolet .. but the problem persists all the same.. I have modified > the gist to reflect this change.. > Sunil. > > On Fri, Nov 26, 2010 at 10:35 AM, Sunil S Nandihalli < > > sunil.nandiha...@gmail.com> wrote: > > Hello everybody, > > I am not sure if this is the expected behaviour .. or I am using it > > incorrectly .. The code is pasted at > >https://gist.github.com/716293. > > > (ns symbol-macro-problem > > > (:require [clojure.contrib.macro-utils :as m])) > > > (defmacro sym-macro [& body] > > > `(m/symbol-macrolet [begin :begin > > > end :end] > > > (m/with-symbol-macros > > > (println begin) > > > ~...@body > > > (println end)))) > > > (defmacro display-local-bindings [] > > > `(do ~@(map (fn [x#] (list 'println [`'~x# x#])) (keys &env)))) > > > (sym-macro > > > (let [x 10] > > > (display-local-bindings))) > > > the above form is not passing the correct &env variable to the nested > > macros .. It is turning out to be nil. The above code just prints > > > :begin > > :end > > > while > > > (let [x 10] > > (display-local-bindings)) > > > prints > > > [x 10] > > > I was expecting the code > > > (sym-macro > > (let [x 10] > > (display-local-bindings))) > > > to print > > > :begin > > [x 10] > > :end > > > but this is not happening since the &env variable that is being passed to > > (display-local-bindings) is nil when called inside a sym-macro > > can somebody help me understand this. > > > Thanks, > > Sunil.
It seems to me that it is probably because the code in macro-utils walks down through the forms and manually calls clojure.core/ macroexpand-1. That calls clojure.lang.Compiler/macroexpand1, which is where the local bindings are normally inserted calls to macros (i.e. the display-local-bindings macro in this case). But it is being called too soon - the compiler has not yet had its chance to walk down through the enclosing forms and collect the local bindings, so it doesn't know what they are. I'm pretty sure that macro-utils predates the addition of the &env paramter. Since macro-utils takes such an aggressive approach to macroexpansion - essentially reimplementing it entirely - it is not too surprising that it would become out of sync with the built-in expansion mechanism. - Chris -- 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