diff options
author | Paul Pogonyshev <pogonyshev@gmail.com> | 2016-03-26 11:19:43 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2016-03-26 11:19:43 +0300 |
commit | 6f3243db55e61847784178ea812f28ddf003544a (patch) | |
tree | e2bbb4e4c3a49ab661524135c6b1a610580431b8 /doc/lispref/functions.texi | |
parent | 368b9bb45f125061506d43af4bd4791ab2cfd7b9 (diff) | |
download | emacs-6f3243db55e61847784178ea812f28ddf003544a.tar.gz |
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.
Diffstat (limited to 'doc/lispref/functions.texi')
-rw-r--r-- | doc/lispref/functions.texi | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index a2e94c34b62..ff21abba61e 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi @@ -143,6 +143,37 @@ function, i.e., can be passed to @code{funcall}. Note that 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 Unlike @code{functionp}, the next three functions do @emph{not} treat a symbol as its function definition. @@ -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 |