A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://lists.gnu.org/archive/html/help-gnu-emacs/2015-08/msg00748.html below:

Re: get nargs for a function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] From: Sam Halliday Subject: Re: get nargs for a function Date: Sat, 29 Aug 2015 15:41:30 -0700 (PDT) User-agent: G2/1.0
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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4