Clojure - How to make my macro expand before system macros?

前端 未结 3 430
我在风中等你
我在风中等你 2021-01-12 06:57

If I do, for example:

(defmacro qqq [] \'(toString [this] \"Qqq\"))
(reify Object (qqq))

it fails because of reify sees

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-12 07:00

    This will work:

    (defn reifyx [x y]
      (eval `(reify ~x ~y)))
    
    (defn qqq [] '(toString [this] "Qqq"))
    
    (reifyx 'Object (qqq))
    

    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 using eval just as I have.

提交回复
热议问题