Created
July 8, 2010 00:13
-
-
Save polypus74/467471 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
(defn dynamic-record [base-name field-names & init-values] | |
(let [klass (eval `(defrecord ~(gensym base-name) ~(vec field-names))) | |
ctor (first (.getConstructors klass)) | |
vals (take (count field-names) | |
(concat init-values (repeat nil)))] | |
(.newInstance ctor (into-array Object vals)))) | |
(dynamic-record "MyRecord" '(foo bar) :foo) | |
;; -> #:user.MyRecord14544{:foo :foo, :bar nil} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment