all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Sam Halliday <sam.halliday@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: get nargs for a function
Date: Sat, 29 Aug 2015 15:41:30 -0700 (PDT)	[thread overview]
Message-ID: <3b735611-f4c0-419d-9938-ab5dc45c0405@googlegroups.com> (raw)
In-Reply-To: <mailman.164.1440884507.19560.help-gnu-emacs@gnu.org>

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.


  parent reply	other threads:[~2015-08-29 22:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-28 16:55 get nargs for a function Sam Halliday
2015-08-28 17:10 ` Ian Zimmerman
2015-08-29 21:41 ` Stefan Monnier
     [not found] ` <mailman.164.1440884507.19560.help-gnu-emacs@gnu.org>
2015-08-29 22:41   ` Sam Halliday [this message]
2015-08-30  2:22     ` Stefan Monnier
     [not found]     ` <mailman.178.1440901363.19560.help-gnu-emacs@gnu.org>
2015-08-30 14:14       ` Sam Halliday
2015-08-31  0:17         ` Stefan Monnier
     [not found]         ` <mailman.227.1440980264.19560.help-gnu-emacs@gnu.org>
2015-09-01 11:30           ` Sam Halliday

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3b735611-f4c0-419d-9938-ab5dc45c0405@googlegroups.com \
    --to=sam.halliday@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.