Skip to content

Commit 3988e93

Browse files
committed
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 4430a9b)
1 parent 7565d2d commit 3988e93

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

doc/lispref/customize.texi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -950,10 +950,10 @@ possibilities:
950950

951951
@itemize @bullet
952952
@item
953-
A predicate---that is, a function of one argument that has no side
954-
effects, and returns either @code{nil} or non-@code{nil} according to
955-
the argument. Using a predicate in the list says that objects for which
956-
the predicate returns non-@code{nil} are acceptable.
953+
A predicate---that is, a function of one argument that returns either
954+
@code{nil} or non-@code{nil} according to the argument. Using a
955+
predicate in the list says that objects for which the predicate
956+
returns non-@code{nil} are acceptable.
957957

958958
@item
959959
A quoted constant---that is, @code{'@var{object}}. This sort of element

doc/lispref/eval.texi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ also temporarily alter the environment by binding variables
8686
(@pxref{Local Variables}).
8787

8888
@cindex side effect
89+
@anchor{Definition of side effect}
8990
Evaluating a form may also make changes that persist; these changes
9091
are called @dfn{side effects}. An example of a form that produces a
9192
side effect is @code{(setq foo 1)}.

doc/lispref/functions.texi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,16 @@ define them.
3838
@cindex return value
3939
@cindex value of function
4040
@cindex argument
41+
@cindex pure function
4142
In a general sense, a function is a rule for carrying out a
4243
computation given input values called @dfn{arguments}. The result of
4344
the computation is called the @dfn{value} or @dfn{return value} of the
4445
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.
4651

4752
In most computer languages, every function has a name. But in Lisp,
4853
a function in the strictest sense has no name: it is an object which

doc/lispref/internals.texi

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -976,10 +976,9 @@ number of arguments. They work by calling @code{Ffuncall}.
976976
@file{lisp.h} contains the definitions for some important macros and
977977
functions.
978978

979-
If you define a function which is side-effect free, update the code
980-
in @file{byte-opt.el} that binds @code{side-effect-free-fns} and
981-
@code{side-effect-and-error-free-fns} so that the compiler optimizer
982-
knows about it.
979+
If you define a function which is side-effect free or pure, give it
980+
a non-@code{nil} @code{side-effect-free} or @code{pure} property,
981+
respectively (@pxref{Standard Properties}).
983982

984983
@node Writing Dynamic Modules
985984
@section Writing Dynamically-Loaded Modules

doc/lispref/symbols.texi

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,12 @@ deleted from the local value of a hook variable when changing major
558558
modes. @xref{Setting Hooks}.
559559

560560
@item pure
561+
@cindex @code{pure} property
561562
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-
compile time. This may shift run time errors to compile time.
563+
pure (@pxref{What Is a Function}). Calls with constant arguments can
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}).
564567

565568
@item risky-local-variable
566569
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
579582
for the named variable. @xref{File Local Variables}.
580583

581584
@item side-effect-free
585+
@cindex @code{side-effect-free} property
582586
A non-@code{nil} value indicates that the named function is free of
583-
side-effects, for determining function safety (@pxref{Function
584-
Safety}) as well as for byte compiler optimizations. Do not set it.
587+
side effects (@pxref{What Is a Function}), so the byte compiler may
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}).
585592

586593
@item variable-documentation
587594
If non-@code{nil}, this specifies the named variable's documentation

0 commit comments

Comments
 (0)