diff options
| author | Paul Pogonyshev | 2016-03-26 11:19:43 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2016-03-26 11:19:43 +0300 |
| commit | 6f3243db55e61847784178ea812f28ddf003544a (patch) | |
| tree | e2bbb4e4c3a49ab661524135c6b1a610580431b8 /doc | |
| parent | 368b9bb45f125061506d43af4bd4791ab2cfd7b9 (diff) | |
| download | emacs-6f3243db55e61847784178ea812f28ddf003544a.tar.gz emacs-6f3243db55e61847784178ea812f28ddf003544a.zip | |
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')
| -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 | |||
| 143 | and returns @code{nil} for special forms. | 143 | and returns @code{nil} for special forms. |
| 144 | @end defun | 144 | @end defun |
| 145 | 145 | ||
| 146 | It is also possible to find out how many arguments an arbitrary | ||
| 147 | function expects: | ||
| 148 | |||
| 149 | @defun func-arity function | ||
| 150 | This function provides information about the argument list of the | ||
| 151 | specified @var{function}. The returned value is a cons cell of the | ||
| 152 | form @w{@code{(@var{min} . @var{max})}}, where @var{min} is the | ||
| 153 | minimum number of arguments, and @var{max} is either the maximum | ||
| 154 | number of arguments, or the symbol @code{many} for functions with | ||
| 155 | @code{&rest} arguments, or the symbol @code{unevalled} if | ||
| 156 | @var{function} is a special form. | ||
| 157 | |||
| 158 | Note that this function might return inaccurate results in some | ||
| 159 | situations, such as the following: | ||
| 160 | |||
| 161 | @itemize @minus | ||
| 162 | @item | ||
| 163 | Functions defined using @code{apply-partially} (@pxref{Calling | ||
| 164 | Functions, apply-partially}). | ||
| 165 | |||
| 166 | @item | ||
| 167 | Functions that are advised using @code{advice-add} (@pxref{Advising | ||
| 168 | Named Functions}). | ||
| 169 | |||
| 170 | @item | ||
| 171 | Functions that determine the argument list dynamically, as part of | ||
| 172 | their code. | ||
| 173 | @end itemize | ||
| 174 | |||
| 175 | @end defun | ||
| 176 | |||
| 146 | @noindent | 177 | @noindent |
| 147 | Unlike @code{functionp}, the next three functions do @emph{not} treat | 178 | Unlike @code{functionp}, the next three functions do @emph{not} treat |
| 148 | a symbol as its function definition. | 179 | a symbol as its function definition. |
| @@ -176,12 +207,9 @@ function. For example: | |||
| 176 | @end defun | 207 | @end defun |
| 177 | 208 | ||
| 178 | @defun subr-arity subr | 209 | @defun subr-arity subr |
| 179 | This function provides information about the argument list of a | 210 | This works like @code{func-arity}, but only for built-in functions and |
| 180 | primitive, @var{subr}. The returned value is a pair | 211 | without symbol indirection. It signals an error for non-built-in |
| 181 | @code{(@var{min} . @var{max})}. @var{min} is the minimum number of | 212 | functions. We recommend to use @code{func-arity} instead. |
| 182 | args. @var{max} is the maximum number or the symbol @code{many}, for a | ||
| 183 | function with @code{&rest} arguments, or the symbol @code{unevalled} if | ||
| 184 | @var{subr} is a special form. | ||
| 185 | @end defun | 213 | @end defun |
| 186 | 214 | ||
| 187 | @node Lambda Expressions | 215 | @node Lambda Expressions |