emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arbitrary function: find the number(s) of expected arguments


From: Eli Zaretskii
Subject: Re: Arbitrary function: find the number(s) of expected arguments
Date: Sat, 19 Mar 2016 20:09:22 +0200

> Date: Sat, 19 Mar 2016 17:51:39 +0100
> From: Paul Pogonyshev <address@hidden>
> Cc: address@hidden
> 
> Approximate patch, without documentation. If this is accepted, I can write 
> documentation too. I submitted
> legal papers for FSF years ago.

Thanks.  A few comments below.  Let's wait for a few days to give
others a chance to comment.

> (func-arity 'car) (1 . 1)
> (func-arity 'caar) (1 . 1)
> (func-arity 'magit-log-all) (0 . 2)
> (func-arity 'format) (1 . many)
> (func-arity (lambda (&rest x))) (0 . many)

How about adding a few tests for this in test/ ?

> +Lisp_Object
> +get_byte_code_arity (Lisp_Object args_template)
> +{
> +  if (INTEGERP (args_template))
> +    {
> +      ptrdiff_t at = XINT (args_template);
> +      bool rest = (at & 128) != 0;
> +      int mandatory = at & 127;
> +      ptrdiff_t nonrest = at >> 8;
> +
> +      return Fcons (make_number (mandatory), rest ? Qmany : make_number 
> (nonrest));
> +    }
> +  else
> +    error ("Unknown args template!");

It could also be a list (that was the old style).  Maybe we should
also support that, in case some old byte-compiled file is used?  I
think you already have the necessary code in lambda_arity.

> +  if (SUBRP (function))
> +    {
> +      minargs = XSUBR (function)->min_args;
> +      maxargs = XSUBR (function)->max_args;
> +      result  = Fcons (make_number (minargs),
> +                       maxargs == MANY ?        Qmany
> +                       : maxargs == UNEVALLED ? Qunevalled
> +                       :                        make_number (maxargs));
> +    }

We have sub-arity, so I think we should remove it and leave an alias
that will call this new function for backward compatibility.  Having
both sounds redundant.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]