1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Implement 'func-arity'

* src/eval.c (Ffunc_arity, lambda_arity): New functions.
* src/bytecode.c (get_byte_code_arity): New function.
* src/lisp.h (get_byte_code_arity): Add prototype.

* doc/lispref/functions.texi (What Is a Function): Document
'func-arity'.

* etc/NEWS: Mention 'func-arity'.

* test/src/fns-tests.el (fns-tests-func-arity): New test set.
This commit is contained in:
Paul Pogonyshev 2016-03-26 11:19:43 +03:00 committed by Eli Zaretskii
parent 368b9bb45f
commit 6f3243db55
6 changed files with 182 additions and 6 deletions

View file

@ -141,6 +141,37 @@ This function returns @code{t} if @var{object} is any kind of
function, i.e., can be passed to @code{funcall}. Note that
@code{functionp} returns @code{t} for symbols that are function names,
and returns @code{nil} for special forms.
@end defun
It is also possible to find out how many arguments an arbitrary
function expects:
@defun func-arity function
This function provides information about the argument list of the
specified @var{function}. The returned value is a cons cell of the
form @w{@code{(@var{min} . @var{max})}}, where @var{min} is the
minimum number of arguments, and @var{max} is either the maximum
number of arguments, or the symbol @code{many} for functions with
@code{&rest} arguments, or the symbol @code{unevalled} if
@var{function} is a special form.
Note that this function might return inaccurate results in some
situations, such as the following:
@itemize @minus
@item
Functions defined using @code{apply-partially} (@pxref{Calling
Functions, apply-partially}).
@item
Functions that are advised using @code{advice-add} (@pxref{Advising
Named Functions}).
@item
Functions that determine the argument list dynamically, as part of
their code.
@end itemize
@end defun
@noindent
@ -176,12 +207,9 @@ function. For example:
@end defun
@defun subr-arity subr
This function provides information about the argument list of a
primitive, @var{subr}. The returned value is a pair
@code{(@var{min} . @var{max})}. @var{min} is the minimum number of
args. @var{max} is the maximum number or the symbol @code{many}, for a
function with @code{&rest} arguments, or the symbol @code{unevalled} if
@var{subr} is a special form.
This works like @code{func-arity}, but only for built-in functions and
without symbol indirection. It signals an error for non-built-in
functions. We recommend to use @code{func-arity} instead.
@end defun
@node Lambda Expressions