Given a function object or name, how can I determine its arity? Something like (arity func-name) .
(arity func-name)
I hope there is a way, since arity is pretty central in C
Sneaky reflection:
(defn arg-count [f] (let [m (first (.getDeclaredMethods (class f))) p (.getParameterTypes m)] (alength p)))
Or :
(defn arg-count [f] {:pre [(instance? clojure.lang.AFunction f)]} (-> f class .getDeclaredMethods first .getParameterTypes alength))