Binding isn't suppose to work for macros. Macros expand during compile-time, and binding only affects vars at runtime. (and) expands into let* and if, neither of which you can bind because they are special rather than being vars/functions -- see (macroexpand `(and 1 2)). Similary, fn expands to fn* which is special and defn expands to def which is special. I can't say if something use to work or not, but I don't think it should.
You might be able to define your own version of defn. Change the ns declaration of your code to exclude defn or fn from the namespace, define your own versions (macros that explicitly expand to clojure/fn or clojure/defn), then code in the rest of the namespace will use your macros. Another way is to redefine the functions you want after the normal definitions are done. This is adapted from some code I wrote to do a similar thing. (defmacro instrument-fns [& fn-symbols] (let [gens (map #(gensym (name %)) fn-symbols)] `(let ~(into [] (interleave gens fn-symbols)) (do ~@(loop [gens gens fn-symbols fn-symbols ret []] (if (seq fn-symbols) (recur (rest gens) (rest fn-symbols) (conj ret `(defn ~(first fn-symbols) [& more#] ;; your instrument code here (apply ~(first gens) more#)))) ret)) )))) Then call it: (instrument-fns myfn1 myfn2 ...) Yet another way might be to use binding around the call to load a file. I don't know what var to bind, nor if there actually is one since much of this code is written in Java. -Mike On Thu, Oct 23, 2008 at 11:33 AM, MikeM <[EMAIL PROTECTED]> wrote: > > In SVN 1075, binding doesn't seem to work for macros: > > ;defined as fn to avoid "can't take value of a macro" exception > (defn bind-test > [& args] `(println "bind-test" [EMAIL PROTECTED])) > > (binding [and bind-test] > (and 1)) > > I recall this used to work (from some experiments I ran in May of > this year). Since the macro flag of the var 'and' is set, my bind-test > fn should be applied as a macro inside the binding. > > I am working on a thread monitoring facility and would like to be able > to : > > (binding [fn my-fn] > ...define functions here using the usual defn and fn macros > ) > > where my-fn adds some instrumenting code to functions. > > > --~--~---------~--~----~------------~-------~--~----~ 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 To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---