From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: How many parameters does an elisp function take? Date: Wed, 16 Feb 2005 16:56:47 -0700 Message-ID: <37i4u2F5b1ro7U1@individual.net> References: <9e90vc.o7.ln@acm.acm> <37hpndF5cn882U1@individual.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1108598363 15401 80.91.229.2 (16 Feb 2005 23:59:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 16 Feb 2005 23:59:23 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Feb 17 00:59:23 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D1Z4Y-00013R-3u for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Feb 2005 00:59:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D1ZKZ-0002qs-Sh for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Feb 2005 19:15:43 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-X-Trace: individual.net OyMNK81bjfc1WpFbfeSu1wW4LXdOwPBErfjxRPnkWSeaXQLqE= User-Agent: Mozilla Thunderbird 0.9 (X11/20041105) X-Accept-Language: en-us, en In-Reply-To: Original-Xref: shelby.stanford.edu gnu.emacs.help:128613 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org X-MailScanner-To: geh-help-gnu-emacs@m.gmane.org Xref: main.gmane.org gmane.emacs.help:24144 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24144 David Kastrup wrote: > Kevin Rodgers 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