
From:  Kevin Rodgers 
Subject:  Re: How many parameters does an elisp function take? 
Date:  Wed, 16 Feb 2005 16:56:47 0700 
Useragent:  Mozilla Thunderbird 0.9 (X11/20041105) 
David Kastrup wrote:
Kevin Rodgers <address@hidden> 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: (howmanyparams '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 eldocfunctionarglist.For builtin functions, subrarity might help.
And now for lisp functions, lambdaarity: (require 'eldoc) (defun lambdaarity (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 (eldocfunctionarglist function)) (optionalarglist (memq '&optional arglist)) (restarglist (memq '&rest arglist))) (cons ( (length arglist) (cond (optionalarglist (length optionalarglist)) (restarglist (length restarglist)) (t 0))) (cond (restarglist 'many) (optionalarglist (+ (length arglist) (length optionalarglist) 1)) (t (length arglist))))))  Kevin Rodgers
[Prev in Thread]  Current Thread  [Next in Thread] 