Define an algebraic data type name by an exhaustive list of constructors.
Each constructor can be a symbol (argument-free constructor) or a
list consisting of a tag symbol followed by the argument symbols.
The data type tag must be a keyword.
(defmacro defadt
"Define an algebraic data type name by an exhaustive list of constructors.
Each constructor can be a symbol (argument-free constructor) or a
list consisting of a tag symbol followed by the argument symbols.
The data type tag must be a keyword."
[type-tag & constructors]
(let [meta-map-symbol (gensym "mm")]
`(let [~meta-map-symbol {:type ~type-tag}]
(derive ~type-tag ::adt)
~@(map (partial constructor-code meta-map-symbol) constructors)
)))
Comments top
No comments for defadt. Log in to add a comment.