Created
September 28, 2010 23:23
-
-
Save nathanmarz/602003 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 constructor-num-args [klass] | |
(let [constrs (.getConstructors klass)] | |
(set | |
(for [c constrs] | |
(count (.getParameterTypes c)) | |
)) | |
)) | |
(defn- mk-fn-inst [klass numargs] | |
(let [args (vec (for [i (range numargs)] (symbol (str "arg" i))))] | |
`(~args (new ~(symbol (.getName klass)) ~@args)) | |
)) | |
(defn factory-fn [klass] | |
(let [insts (for [i (constructor-num-args klass)] (mk-fn-inst klass i))] | |
(eval `(fn ~@insts)) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment