I'm looking for a way to get the amount of arguments of a function, a function like the imaginary length-args function below:
(defun func1 (arg1 arg2)
())
(defun get-count-args-func (func)
(length-args func))
(get-count-args-func #'func1)
;; return 2
In practice what I really need is to solve a question from my test library that I am bringing from javascript to lisp, where I deal both with synchronous and asynchronous tests, where I need to do something like this(simplifying to the maximum the reality):
(defun test ()
;;...
)
(defun done ()
;;...
)
(defun run-test (test)
(if (>= (get-count-args-func test) 1)
(test (funcall done))
(test)))
I found a way to resolve this issue by looking at this answer here: Find Function's Arity in common lisp, an arglist function is required to handle the various implementations, see the implementation of arglist:
Now I can do:
So I have the number of arguments, you just have to be attentive, if you have some
&keyargument,&restor&optional, for example:See that you get 3, because what arglist function is returning:
while only with required arguments he returned: