Skip to content

Instantly share code, notes, and snippets.

@mrBliss
Created October 3, 2010 15:31
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 mrBliss/608662 to your computer and use it in GitHub Desktop.
Save mrBliss/608662 to your computer and use it in GitHub Desktop.
(defmacro create
"Dynamic factory for defrecords."
([name] `(create ~name {}) )
([name vals-map]
`(let [con# (first (.getDeclaredConstructors ~name))
num# (alength (.getParameterTypes
^java.lang.reflect.Constructor con#))]
(merge (.newInstance ^java.lang.reflect.Constructor
con# (make-array Object num#)) ~vals-map))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment