Clojure: How to find out the arity of function at runtime?

前端 未结 7 1406
野趣味
野趣味 2021-01-31 02:08

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

相关标签:
7条回答
  • 2021-01-31 02:47

    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.

    0 讨论(0)
提交回复
热议问题