From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sam Halliday Newsgroups: gmane.emacs.help Subject: Re: get nargs for a function Date: Sat, 29 Aug 2015 15:41:30 -0700 (PDT) Message-ID: <3b735611-f4c0-419d-9938-ab5dc45c0405@googlegroups.com> References: <9eb51198-614a-49f7-8085-2a068dd28852@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1440888319 21729 80.91.229.3 (29 Aug 2015 22:45:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 29 Aug 2015 22:45:19 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 30 00:45:18 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZVos9-0008VN-5n for geh-help-gnu-emacs@m.gmane.org; Sun, 30 Aug 2015 00:45:17 +0200 Original-Received: from localhost ([::1]:55093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZVos9-0003Ou-4d for geh-help-gnu-emacs@m.gmane.org; Sat, 29 Aug 2015 18:45:17 -0400 X-Received: by 10.66.136.205 with SMTP id qc13mr17864885pab.7.1440888091247; Sat, 29 Aug 2015 15:41:31 -0700 (PDT) X-Received: by 10.50.40.42 with SMTP id u10mr142301igk.14.1440888091217; Sat, 29 Aug 2015 15:41:31 -0700 (PDT) Original-Path: usenet.stanford.edu!rd18no24073igc.0!news-out.google.com!f6ni9186igi.0!nntp.google.com!rd18no24064igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=89.241.69.172; posting-account=kRukCAoAAAANs-vsVh9dFwo5kp5pwnPz Original-NNTP-Posting-Host: 89.241.69.172 User-Agent: G2/1.0 Injection-Date: Sat, 29 Aug 2015 22:41:31 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.help:214641 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:106925 Archived-At: On Saturday, 29 August 2015 22:41:49 UTC+1, Stefan Monnier wrote: > > Is there a built in way to return the arg list (actually just the number of > > args) for a function that has been passed to me? > > The answer is "yes, but fundamentally no". > The reason it's fundamentally no, is that you'd need to answer questions > such as "how many arguments does cl-member take". > > In most cases, the better approach is to do something else, such as: > > (condition-case > (funcall thefunction arg1 arg2 ...) > (wrong-number-of-arguments > ...do-something-else...)) This is only to answer a toy problem anyway so good to know this doesn't scale. I ended up doing this (defun args (function) "The arg list of FUNCTION." (let ((kind (car function))) (if (eq kind 'closure) (cadr (cdr function)) (cadr function)))) because the nature of the problem required working on a function with an arbitrary argument list. https://github.com/fommil/e99/blob/master/48.el I suppose I could re-interpret the question to take the nargs explicitly.