Created
January 18, 2017 12:35
-
-
Save Jannis/af5c0dfed612fae19cb7b38705ad561c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Query: A vector of keywords (e.g. [:foo :bar]) | |
(defmacro with-query-bindings | |
"Binds names derived from a query to the results for the query. | |
E.g. the query [:foo :bar] is turned into | |
(let [{foo :foo bar :bar} <query result>] | |
<body>)" | |
[query query-result & body] | |
(let [bindings (query-bindings query)] | |
`(let [~bindings ~query-result] | |
~@body))) | |
(defmacro foo | |
[query query-result & body] | |
`(with-query-bindings ~query ~query-result | |
~@body)) | |
;; Works fine | |
(foo | |
[:foo :bar] ; Query | |
{:foo "VALUE OF FOO" :bar "VALUE OF BAR"} ; Query result | |
(println foo) ; Body | |
(println bar)) | |
;; I'd like this to work as well: | |
(defn make-query [] | |
[:foo :bar]) | |
(foo | |
(make-query) ; Query generating expression | |
{:foo "VALUE OF FOO" :bar "VALUE OF BAR"} ; Query result | |
(println foo) ; Body | |
(println bar)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment