I have the following macro:
(defmacro ss [x]
`(clojureql.core/select
(clojureql.core/table db "users_table")
(clojureql.core/where ~x)
)
)
(macroexpand '(ss '(= :type "special")))
: but it produces :
(clojureql.core/select (clojureql.core/table oe.db.dbcore/db "users_table") (clojureql.core/where '(= :type "special")))
: instead of :
(clojureql.core/select (clojureql.core/table oe.db.dbcore/db "users_table") (clojureql.core/where (= :type "special")))
: I realise that the problem is I am passing in a list '(= :type "special"), but how can I get this to unquote in the macro?
Update:
I finally got this working thanks to Mikera's answer by doing this:
(defn ss [x]
(clojureql.core/select
(clojureql.core/table db "users_table")
x
)
)
(macroexpand '(ss (eval `(clojureql.core/where ~'(= :type "special")))))
: although the output is slightly different it works as expected:
(ss (eval (clojure.core/seq (clojure.core/concat (clojure.core/list 'clojureql.core/where) (clojure.core/list '(= :type "special"))))))
evalin such case. Just change ~x to ~(eval x). But I don't know, maybe there is another solution or you just misspelled with (= :type "special").evalis working (I tried (defmacro ss [x] `(* 3 ~(eval x))) (macroexpand '(ss '(+ 1 2)))). But if the code is expanded to (quote (= :type "special")) then I come to only one solution: to use ~(second x). But don't know why I don't like it. :)