Last active
December 4, 2017 07:54
-
-
Save rauhs/d2575e77e6e063ae94abbd9f1bca226d 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
;; FROM: https://github.com/gfredericks/misquote | |
(defn- listish? | |
"Gets both lists and lazy seqs." | |
[ob] | |
(and (sequential? ob) (not (vector? ob)))) | |
(defn- unquote-form? | |
[form] | |
(and (listish? form) | |
(= 'clojure.core/unquote (first form)))) | |
(defn- unquote-splicing-form? | |
[form] | |
(and (listish? form) | |
(= 'clojure.core/unquote-splicing (first form)))) | |
(def ^{:arglists '([x])} scalar? | |
(some-fn number? true? false? nil? keyword? symbol? string?)) | |
(defn misquote' | |
[arg] | |
(cond | |
(unquote-form? arg) | |
(second arg) | |
(vector? arg) | |
`(vec ~(misquote' (seq arg))) | |
(set? arg) | |
`(set ~(misquote' (seq arg))) | |
(map? arg) | |
`(into {} ~(misquote' (map vec arg))) | |
(listish? arg) | |
(cons `concat | |
(for [x arg] | |
(cond (unquote-form? x) | |
[(second x)] | |
(unquote-splicing-form? x) | |
(second x) | |
:else | |
[(misquote' x)]))) | |
(scalar? arg) (list 'quote arg))) | |
(defmacro misquote | |
"Like quote but can use the unquote operator (~) for eval. | |
(misquote '[:foo ~bar])" | |
[arg] | |
(misquote' (second arg))) |
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
(def query-pull-pattern | |
"The query pull pattern to get schema/propt/(post)-display" | |
[:query/id | |
{:query/schema [:schema/id :schema/official?]} | |
{:query/prompt [:schema.field/name]} | |
{:query/display [:schema.field/name]} | |
{:query/post-display [:schema.field/name]}]) | |
(mq/misquote | |
'[:find [(pull ?e ~query-pull-pattern) ...] | |
:in $ ?sch-id | |
:where | |
[?sch :schema/id ?sch-id] | |
[?e :query/schema ?sch]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment