On Sat, Apr 10, 2010 at 7:48 AM, Douglas Philips <d...@mac.com> wrote:
> Odd:
>  user=> (binding [m1 (fn [a b] (println "m1 from binding" a b))]
>                  (eval '(if true (m1 "true" "here") (m1 "false" "there"))))
>  m1 from binding true here
>  m1 from binding false there
>  nil

That doesn't even run for me on HEAD. But I can guess what's going on
from a small experiment:

user> (defmacro m [x y] `(println ~x ~y))
#'user/m
user> (binding [m (fn [x y] (println "override") nil)] (meta #'m))
{:macro true, :ns #<Namespace user>, :name m, :file "NO_SOURCE_FILE",
:line 1, :arglists ([x y])}

The difference between a function and a macro is a flag in the
metadata flag. Metadata is a feature of the container (the var) rather
than the contents. So when you rebind a var that was created by
defmacro, you retain the macrohood of the root. That means it's
invoking your function as a macro at compile time rather than as a
function at run time.

-Per

-- 
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

To unsubscribe, reply using "remove me" as the subject.

Reply via email to