Given a function object or name, how can I determine its arity? Something like (arity func-name)
.
I hope there is a way, since arity is pretty central in C
My take at the arity problem, building on the other solutions:
(defn arity
"Returns the maximum parameter count of each invoke method found by refletion
on the input instance. The returned value can be then interpreted as the arity
of the input function. The count does NOT detect variadic functions."
[f]
(let [invokes (filter #(= "invoke" (.getName %1)) (.getDeclaredMethods (class f)))]
(apply max (map #(alength (.getParameterTypes %1)) invokes))))