How can I determine number of arguments to a function in Clojure?

后端 未结 2 919
暖寄归人
暖寄归人 2021-02-13 02:14

Given a function x in clojure how can I programatically get a count of the number of arguments?

eg:

(fn a [b c] ...) has has two arguments
(fn a [] ...)          


        
2条回答
  •  执笔经年
    2021-02-13 02:58

    You could construct a function taking all arguments, putting them in a list and returning the count like so:

    (defn arg-count [& rest] (count rest))
    (arg-count) ;; 0
    (arg-count 1 2 3) ;; 3
    

提交回复
热议问题