diff options
| author | Basil L. Contovounesios | 2019-04-17 16:34:47 +0100 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-04-22 16:14:33 +0100 |
| commit | 3988e93d4b0f2bf677efd9f560373dd526097609 (patch) | |
| tree | 003dad909c9179da24a6501ce96ea17282382de2 | |
| parent | 7565d2d2fbc8eec314d40e2e99992c8864307e1b (diff) | |
| download | emacs-3988e93d4b0f2bf677efd9f560373dd526097609.tar.gz emacs-3988e93d4b0f2bf677efd9f560373dd526097609.zip | |
Backport: Improve pure and side-effect-free docs
For discussion, see thread starting at:
https://lists.gnu.org/archive/html/emacs-devel/2019-04/msg00316.html
* doc/lispref/customize.texi (Composite Types): Do not overspecify
:match-alternatives predicates.
* doc/lispref/eval.texi (Intro Eval): Anchor definition of "side
effect" for cross-referencing...
* doc/lispref/functions.texi (What Is a Function): ...from here.
Define what a pure function is.
* doc/lispref/internals.texi (Writing Emacs Primitives): Describe
currently preferred approach to marking primitives as pure and
side-effect-free.
* doc/lispref/symbols.texi (Standard Properties): Expand description
of pure and side-effect-free properties.
(cherry picked from commit 4430a9b54fca266e48d0eb8b72d83706910f10b8)
| -rw-r--r-- | doc/lispref/customize.texi | 8 | ||||
| -rw-r--r-- | doc/lispref/eval.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/functions.texi | 7 | ||||
| -rw-r--r-- | doc/lispref/internals.texi | 7 | ||||
| -rw-r--r-- | doc/lispref/symbols.texi | 15 |
5 files changed, 25 insertions, 13 deletions
diff --git a/doc/lispref/customize.texi b/doc/lispref/customize.texi index f71dedfd8b0..02eefe0f585 100644 --- a/doc/lispref/customize.texi +++ b/doc/lispref/customize.texi | |||
| @@ -950,10 +950,10 @@ possibilities: | |||
| 950 | 950 | ||
| 951 | @itemize @bullet | 951 | @itemize @bullet |
| 952 | @item | 952 | @item |
| 953 | A predicate---that is, a function of one argument that has no side | 953 | A predicate---that is, a function of one argument that returns either |
| 954 | effects, and returns either @code{nil} or non-@code{nil} according to | 954 | @code{nil} or non-@code{nil} according to the argument. Using a |
| 955 | the argument. Using a predicate in the list says that objects for which | 955 | predicate in the list says that objects for which the predicate |
| 956 | the predicate returns non-@code{nil} are acceptable. | 956 | returns non-@code{nil} are acceptable. |
| 957 | 957 | ||
| 958 | @item | 958 | @item |
| 959 | A quoted constant---that is, @code{'@var{object}}. This sort of element | 959 | A quoted constant---that is, @code{'@var{object}}. This sort of element |
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index 4bf70d247b6..73f5396dabe 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -86,6 +86,7 @@ also temporarily alter the environment by binding variables | |||
| 86 | (@pxref{Local Variables}). | 86 | (@pxref{Local Variables}). |
| 87 | 87 | ||
| 88 | @cindex side effect | 88 | @cindex side effect |
| 89 | @anchor{Definition of side effect} | ||
| 89 | Evaluating a form may also make changes that persist; these changes | 90 | Evaluating a form may also make changes that persist; these changes |
| 90 | are called @dfn{side effects}. An example of a form that produces a | 91 | are called @dfn{side effects}. An example of a form that produces a |
| 91 | side effect is @code{(setq foo 1)}. | 92 | side effect is @code{(setq foo 1)}. |
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index d01804e4940..f641fe7024a 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi | |||
| @@ -38,11 +38,16 @@ define them. | |||
| 38 | @cindex return value | 38 | @cindex return value |
| 39 | @cindex value of function | 39 | @cindex value of function |
| 40 | @cindex argument | 40 | @cindex argument |
| 41 | @cindex pure function | ||
| 41 | In a general sense, a function is a rule for carrying out a | 42 | In a general sense, a function is a rule for carrying out a |
| 42 | computation given input values called @dfn{arguments}. The result of | 43 | computation given input values called @dfn{arguments}. The result of |
| 43 | the computation is called the @dfn{value} or @dfn{return value} of the | 44 | the computation is called the @dfn{value} or @dfn{return value} of the |
| 44 | function. The computation can also have side effects, such as lasting | 45 | function. The computation can also have side effects, such as lasting |
| 45 | changes in the values of variables or the contents of data structures. | 46 | changes in the values of variables or the contents of data structures |
| 47 | (@pxref{Definition of side effect}). A @dfn{pure function} is a | ||
| 48 | function which, in addition to having no side effects, always returns | ||
| 49 | the same value for the same combination of arguments, regardless of | ||
| 50 | external factors such as machine type or system state. | ||
| 46 | 51 | ||
| 47 | In most computer languages, every function has a name. But in Lisp, | 52 | In most computer languages, every function has a name. But in Lisp, |
| 48 | a function in the strictest sense has no name: it is an object which | 53 | a function in the strictest sense has no name: it is an object which |
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi index 38d84f149e0..62a102e3845 100644 --- a/doc/lispref/internals.texi +++ b/doc/lispref/internals.texi | |||
| @@ -976,10 +976,9 @@ number of arguments. They work by calling @code{Ffuncall}. | |||
| 976 | @file{lisp.h} contains the definitions for some important macros and | 976 | @file{lisp.h} contains the definitions for some important macros and |
| 977 | functions. | 977 | functions. |
| 978 | 978 | ||
| 979 | If you define a function which is side-effect free, update the code | 979 | If you define a function which is side-effect free or pure, give it |
| 980 | in @file{byte-opt.el} that binds @code{side-effect-free-fns} and | 980 | a non-@code{nil} @code{side-effect-free} or @code{pure} property, |
| 981 | @code{side-effect-and-error-free-fns} so that the compiler optimizer | 981 | respectively (@pxref{Standard Properties}). |
| 982 | knows about it. | ||
| 983 | 982 | ||
| 984 | @node Writing Dynamic Modules | 983 | @node Writing Dynamic Modules |
| 985 | @section Writing Dynamically-Loaded Modules | 984 | @section Writing Dynamically-Loaded Modules |
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi index a214a2d3fd8..5d71fb39a25 100644 --- a/doc/lispref/symbols.texi +++ b/doc/lispref/symbols.texi | |||
| @@ -558,9 +558,12 @@ deleted from the local value of a hook variable when changing major | |||
| 558 | modes. @xref{Setting Hooks}. | 558 | modes. @xref{Setting Hooks}. |
| 559 | 559 | ||
| 560 | @item pure | 560 | @item pure |
| 561 | @cindex @code{pure} property | ||
| 561 | If the value is non-@code{nil}, the named function is considered to be | 562 | If the value is non-@code{nil}, the named function is considered to be |
| 562 | side-effect free. Calls with constant arguments can be evaluated at | 563 | pure (@pxref{What Is a Function}). Calls with constant arguments can |
| 563 | compile time. This may shift run time errors to compile time. | 564 | be evaluated at compile time. This may shift run time errors to |
| 565 | compile time. Not to be confused with pure storage (@pxref{Pure | ||
| 566 | Storage}). | ||
| 564 | 567 | ||
| 565 | @item risky-local-variable | 568 | @item risky-local-variable |
| 566 | If the value is non-@code{nil}, the named variable is considered risky | 569 | If the value is non-@code{nil}, the named variable is considered risky |
| @@ -579,9 +582,13 @@ The value specifies a function for determining safe file-local values | |||
| 579 | for the named variable. @xref{File Local Variables}. | 582 | for the named variable. @xref{File Local Variables}. |
| 580 | 583 | ||
| 581 | @item side-effect-free | 584 | @item side-effect-free |
| 585 | @cindex @code{side-effect-free} property | ||
| 582 | A non-@code{nil} value indicates that the named function is free of | 586 | A non-@code{nil} value indicates that the named function is free of |
| 583 | side-effects, for determining function safety (@pxref{Function | 587 | side effects (@pxref{What Is a Function}), so the byte compiler may |
| 584 | Safety}) as well as for byte compiler optimizations. Do not set it. | 588 | ignore a call whose value is unused. If the property's value is |
| 589 | @code{error-free}, the byte compiler may even delete such unused | ||
| 590 | calls. In addition to byte compiler optimizations, this property is | ||
| 591 | also used for determining function safety (@pxref{Function Safety}). | ||
| 585 | 592 | ||
| 586 | @item variable-documentation | 593 | @item variable-documentation |
| 587 | If non-@code{nil}, this specifies the named variable's documentation | 594 | If non-@code{nil}, this specifies the named variable's documentation |