From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: How many parameters does an elisp function take? Date: Fri, 18 Feb 2005 17:43:55 +0000 Organization: muc.de e.V. -- private internet access Message-ID: References: <9e90vc.o7.ln@acm.acm> <871xbe9dn9.fsf-monnier+gnu.emacs.help@gnu.org> NNTP-Posting-Host: main.gmane.org X-Trace: sea.gmane.org 1108763308 17436 80.91.229.2 (18 Feb 2005 21:48:28 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 18 Feb 2005 21:48:28 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 18 22:48:27 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1D2Fz5-0005Jq-70 for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Feb 2005 22:48:23 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1D2GFV-0000Jf-0q for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Feb 2005 17:05:21 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!informatik.tu-muenchen.de!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 55 Original-NNTP-Posting-Host: acm.muc.de Original-X-Trace: marvin.muc.de 1108762925 48882 193.149.49.134 (18 Feb 2005 21:42:05 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: 18 Feb 2005 21:42:05 GMT User-Agent: tin/1.4.5-20010409 ("One More Nightmare") (UNIX) (Linux/2.0.35 (i686)) Original-Xref: shelby.stanford.edu gnu.emacs.help:128637 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:24168 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:24168 Stefan Monnier wrote on Fri, 18 Feb 2005 08:59:24 -0500: >> 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. > Why do you want to know? I'd like to fix `beginning-of-defun-raw', where it does (funcall beginning-of-defun-function). The parameter `arg' from beginning-of-defun should be passed through to b-o-d-f. We've talked about this before. Unfortunately, there is no guarantee that existing user supplied functions can accept an `arg'. I would thus replace the call with (if (>= (how-many-params beginnin-of-defun-function) 1) (funcall beginning-of-defun-function arg) (funcall beginning-of-defun-function)) > Every time this has shown up for me, what I truly wanted to know was > more like "can I call this with 4 args?", and the reason why I wanted > to know was to know whether to call it with 4 args or otherwise do > something else (e.g. call it with fewer args). Exactly. > In practice, it's simpler to just do > (condition-case nil > (fooo) > (wrong-number-of-arguments > (bar))) > It's not perfect, but I've found it to suffer from fewer problems than > other solutions. It's also faster. Good idea! Why is there not such a function in the Emacs core? It seems such an incredibly useful function, say for debuggers or code-analysers, or for the uses mentioned above. Did somebody just overlook it in the early days, perhaps? > Stefan -- Alan Mackenzie (Munich, Germany) Email: aacm@muuc.dee; to decode, wherever there is a repeated letter (like "aa"), remove half of them (leaving, say, "a").