我有以下宏:
(defmacro ss [x]
`(clojureql.core/select
(clojureql.core/table db "users_table")
(clojureql.core/where ~x)
)
)
(macroexpand '(ss '(= :type "special")))
:但它产生:
(clojureql.core/select (clojureql.core/table oe.db.dbcore/db "users_table") (clojureql.core/where '(= :type "special")))
: 代替 :
(clojureql.core/select (clojureql.core/table oe.db.dbcore/db "users_table") (clojureql.core/where (= :type "special")))
:我意识到问题是我传入了一个列表'(=:type“special”),但是我怎样才能让它在宏中取消引用?
更新:
由于 Mikera 的回答,我终于得到了这个工作:
(defn ss [x]
(clojureql.core/select
(clojureql.core/table db "users_table")
x
)
)
(macroexpand '(ss (eval `(clojureql.core/where ~'(= :type "special")))))
:虽然输出略有不同,但它按预期工作:
(ss (eval (clojure.core/seq (clojure.core/concat (clojure.core/list 'clojureql.core/where) (clojure.core/list '(= :type "special"))))))