Why is there no unquote for quote? Instead of this
(d/q '[:find ?e
:in $ ?alias
:where
[?e :aka ?alias]]
(d/db conn)
name)
we could write
(d/q '[:find ?e
:where
[?e :aka ~name]]
(d/db conn))
.If you want a syntax quote / unquote without namespace qualifying you can take a look at https://github.com/brandonbloom/backtick
i've used backtick many times with good success, the template macro is very useful
There is. It's just that unquote (the actual special behind the ~ sugar) works only with the syntax quote. But then you have the issue where ?e is syntax-quoted, so you'd have to circumvent it with ~'?e.
Ah, I guess that's exactly your question then. :)
The regular quote quotes everything, regardless of specials. Adding an unquote to it would make it not work in any scenarios where you need to, well, quote clojure.core/unquote. There would be some scenarios that are impossible to implement.
You could just quote the symbol ?e in that:
(d/q [:find '?e
:where
['?e :aka name]]
(d/db conn))Or even:
(let [?e '?e]
(d/q [:find ?e :where [?e :aka name]] (d/db conn))Heh, neat. Now it's just a matter of somebody coming over and making letq that lets you (letq [?a ?b ?c] (d/q ...)). :D
(defmacro letsym [syms & body]
(let [bindings (mapcat (fn [sym]
[sym `'~sym]) syms)]
`(let [~@bindings]
~@body)))
(macroexpand-1 '(letsym [?a ?b ?c]
(do-something)))
(let [v 1]
(letsym [?a ?b ?c]
[:find ?a
:where [?a :data/value ?b]
[?b :data/next-val v]]))
😄Before you try to implement such a macro. I have this already: https://clojureverse.org/t/create-code-like-data-structures-dynamically/10903/10?u=habruening But the question is, why does Clojure not have something like this already? And why doesn't Datomic bring data into the query in this way?