Philipp Stephani
schrieb am Sa., 19. März 2016 um
17:34 Uhr:
> Eli Zaretskii schrieb am Sa., 19. März 2016 um 17:33 Uhr:
>
>> > From: Philipp Stephani
>> > Date: Sat, 19 Mar 2016 16:30:30 +0000
>> > Cc: michael_heerdegen@web.de, emacs-devel@gnu.org
>> >
>> > No, that's not g's arity:
>> >
>> > (g 10 202 30) => error -> "Wrong number of arguments"
>> >
>> > This cannot be detected without evaluating the function.
>>
>> Are we discussing the usefulness of the function, or are we discussing
>> how best to implement it?
>>
>
> We are discussing for which cases it can be implemented. It can be
> implemented and would be useful for a wide range of functions, such as
> those defined with defun.
>
Example implementation (doesn't work with macros):
(defun function-arity (function)
(setq function (indirect-function function))
(cl-check-type function function)
(if (subrp function)
(subr-arity function)
(let ((min 0) (max 0) optional)
(dolist (arg (help-function-arglist function) (cons min max))
(cond
((eq max 'many))
((eq arg '&optional) (setq optional t))
((eq arg '&rest) (setq max 'many))
(t
(unless optional (cl-incf min))
(cl-incf max)))))))