-
-
Save cemerick/1d7cdc705e6b71721207 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
(defmacro defrecord+ | |
[name slots & rest] | |
(let [fields (->> slots (partition 2) (map first) vec) | |
defaults (->> slots (partition 2) (map second) vec)] | |
`(do | |
(defrecord ~name | |
~fields | |
~@rest) | |
(defn ~(symbol (str "new-" name)) | |
[] | |
(~(symbol (str name \.)) ~@defaults)) | |
~name))) | |
com.snowtide.pdf=> (defrecord+ Defaulting | |
[a 5 b 7 c {:crazy true}] | |
Object | |
(toString [a] "yay!")) | |
com.snowtide.pdf.Defaulting | |
com.snowtide.pdf=> (new-Defaulting) | |
{:a 5, | |
:b 7, | |
:c {:crazy true}} | |
com.snowtide.pdf=> (.toString *1) | |
"yay!" | |
com.snowtide.pdf=> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment