Inspecting the var's metadata is probably the best way to do this.
If you're not dealing with vars, but anonymous functions, here's a
hackish piece of code that gathers arity information via reflection:
(defn arities [f]
(let [methods (.getDeclaredMethods (class f))
count-params (fn [m] (map #(count (.getParameterTypes %))
(filter #(= m (.getName %))
methods)))
invokes (count-params "invoke")
do-invokes (map dec (count-params "doInvoke"))
arities (sort (distinct (concat invokes do-invokes)))]
(if (seq do-invokes)
(concat arities [:more])
arities)))
user> (arities map)
(2 3 4 :more)
user> (arities (fn ([a b]) ([a b c d]) ([a b c d e f & more])))
(2 4 6 :more)
Beware! This snippet relies on unexposed details of clojure's current
implementation. It might stop working tomorrow, so it's definitely not
intended for production use, but it might help with debbuging/exploring.
Kind Regards,
achim
Beware! This snippet relies on unexposed details of clojure's current
implementation. It might stop working tomorrow, so it's definitely not
intended for production use, but it might help with debbuging/exploring.
Hi!