Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cemerick
Created July 23, 2010 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cemerick/6676bbfb35f305d05825 to your computer and use it in GitHub Desktop.
Save cemerick/6676bbfb35f305d05825 to your computer and use it in GitHub Desktop.
(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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment