emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arbitrary function: find the number(s) of expected arguments


From: Philipp Stephani
Subject: Re: Arbitrary function: find the number(s) of expected arguments
Date: Sat, 19 Mar 2016 16:46:29 +0000



Philipp Stephani <address@hidden> schrieb am Sa., 19. März 2016 um 17:34 Uhr:
Eli Zaretskii <address@hidden> schrieb am Sa., 19. März 2016 um 17:33 Uhr:
> From: Philipp Stephani <address@hidden>
> Date: Sat, 19 Mar 2016 16:30:30 +0000
> Cc: address@hidden, address@hidden
>
>  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)))))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]