macro | since v0.0-3255 | Edit |
(deftype type-name & fields)
(defmacro deftype
[type-name & fields]
(let [name-str (name type-name)
fields (map (comp symbol name) fields)]
`(do
(defrecord ~type-name [~'type-tag ~@fields])
(defn- ~(symbol (str "make-" name-str))
~(vec fields)
(~(symbol (str type-name ".")) ~(keyword name-str) ~@fields))
(defn- ~(symbol (str name-str "?")) [x#] (= (:type-tag x#) ~(keyword name-str))))))