If I do, for example:
(defmacro qqq [] '(toString [this] "Qqq"))
(reify Object (qqq))
it fails because of reify
sees (qqq)
instead of (toString [this] "Qqq")
.
The usual solution is a macro that wraps "reify" call with my own thing, but it is longer and more intrusive.
How to make my macros stronger that usual macros to be expanded first?
Expecting something like:
(defmacro ^{:priority 100500} qqq [] '(toString [this] "Qqq"))
(reify Object (qqq))
or
(defmacro qqq [] '(toString [this] "Qqq"))
(expand-first #{qqq} (reify Object (qqq)))
There is a reader-macro to evaluate things at read-time (before macro-expansion time)..
I've never seen this done in "real" code, and I think most people would consider it a hack, but it's there if you need it.
This will work:
I found an apply-macro. I tried it, but it seems to be broken. The most important thing I gleaned from looking at
apply-macro
was that it solved the problem usingeval
just as I have.The macro that forces given user macros to expand first (requires
clojure.walk
):Who has ideas how to make it better?