Skip to content

Instantly share code, notes, and snippets.

@nathanmarz
Created September 28, 2010 23:23
Show Gist options
  • Save nathanmarz/602003 to your computer and use it in GitHub Desktop.
Save nathanmarz/602003 to your computer and use it in GitHub Desktop.
(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