Clojure: How to find out the arity of function at runtime?
问题 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 Clojure 回答1: The arity of a function is stored in the metadata of the var. (:arglists (meta #'str)) ;([] [x] [x & ys]) This requires that the function was either defined using defn , or the :arglists metadata supplied explicitly. 回答2: Sneaky reflection: (defn arg-count [f] (let [m (first (.getDeclaredMethods (class f))) p (