Clojure - 如何在宏中引用deftype的变量?

时间:2011-02-13 14:00:16

标签: macros clojure deftype

当我这样做时

(defmacro my-deftype [& code] `(deftype ~@code (toString [this] var1)))
(my-deftype Qqq [var1] Object)

它告诉CompilerException ... No such var: mynamespace/var1

如何正确引用宏中的deftype变量?我希望宏为方法提供模板,避免在每个方法中提及所有deftype的变量。

1 个答案:

答案 0 :(得分:2)

~'

应阻止命名空间扩展
(defmacro my-deftype [& code] `(deftype ~@code (toString [~'this] ~'var1)))
(my-deftype Qqq [var1] Object)