Created
November 22, 2012 07:08
-
-
Save brandonbloom/4129774 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
(defn- unquote? [form] | |
(and (seq? form) (= (first form) 'clojure.core/unquote))) | |
(defn- unquote-splicing? [form] | |
(and (seq? form) (= (first form) 'clojure.core/unquote-splicing))) | |
(defn syntax-quote-fn [form] | |
(cond | |
(unquote? form) (second form) | |
(unquote-splicing? form) (throw (Exception. "splice not in list")) | |
(coll? form) | |
(let [xs (if (map? form) (apply concat form) form) | |
cat `(concat ~@(for [x (partition-by unquote-splicing? xs)] | |
(if (unquote-splicing? (first x)) | |
(second (first x)) | |
`[~@(map syntax-quote-fn x)])))] | |
(cond | |
(vector? form) `(vec ~cat) | |
(map? form) `(apply hash-map ~cat) | |
(set? form) `(set ~cat) | |
(seq? form) `(list* ~cat) | |
:else (throw (Exception. "Unknown collection type")))) | |
:else `'~form)) | |
(defmacro syntax-quote [form] | |
`(syntax-quote-fn '~form)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment