David Kastrup wrote:
Kevin Rodgers <[EMAIL PROTECTED]> writes:
Alan Mackenzie wrote:
Is it possible to determine at run time how many parameters an elisp
function takes?  For example, I'd like to write something like:
(how-many-params 'null)
and have it evaluate to 1.  Or something like that.  Together with
some
reasonable convention for indicating &optional and &rest arguments.

I would start with eldoc-function-arglist.

For built-in functions, subr-arity might help.

And now for lisp functions, lambda-arity:

(require 'eldoc)

(defun lambda-arity (function)
  "Return minimum and maximum number of args allowed for FUNCTION.
FUNCTION must be a symbol whose function binding is a lambda expression
or a macro.
The returned value is a pair (MIN . MAX).  MIN is the minimum number
of args.  MAX is the maximum number or the symbol `many', for a lambda
or macro with `&rest' args."
  (let* ((arglist (eldoc-function-arglist function))
         (optional-arglist (memq '&optional arglist))
         (rest-arglist (memq '&rest arglist)))
    (cons (- (length arglist)
             (cond (optional-arglist (length optional-arglist))
                   (rest-arglist (length rest-arglist))
                   (t 0)))
          (cond (rest-arglist 'many)
                (optional-arglist (+ (length arglist)
                                     (length optional-arglist)
                                     -1))
                (t (length arglist))))))

--
Kevin Rodgers
_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

Reply via email to