-
-
Save tdavis/9d8b0f704f1a05f22d0b 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
(ns test) | |
(defn field [f fwd] | |
(if (= :MAGIC f) | |
(schema.core/maybe (schema.core/recursive (intern *ns* fwd))) | |
f)) | |
(defmacro clj-structs [name fields] | |
(let [sym# (symbol name) | |
fwd# (symbol (str "fwd-" name))] | |
`(do | |
(declare ~fwd#) | |
(schema.core/defrecord ~sym# | |
~(vec (reduce concat (map (fn [[k v]] (list (symbol k) :- (field v fwd#))) fields)))) | |
(def ^:private ~fwd# ~sym#)))) | |
(macroexpand '(clj-structs "Thing" {"id" schema.core/Int "other" :MAGIC})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
macroexpand with
(intern...)
:error with `#'~f:
(that
recursive
function makes sure the argument implementsIDeref
)