unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Basil L. Contovounesios" <contovob@tcd.ie>
To: Eli Zaretskii <eliz@gnu.org>
Cc: branham@utexas.edu, monnier@iro.umontreal.ca,
	drew.adams@oracle.com, emacs-devel@gnu.org
Subject: Re: Predicate for true lists
Date: Sun, 21 Apr 2019 22:37:14 +0100	[thread overview]
Message-ID: <87r29v6nw5.fsf@tcd.ie> (raw)
In-Reply-To: <83sgub87wu.fsf@gnu.org> (Eli Zaretskii's message of "Sun, 21 Apr 2019 22:39:29 +0300")

[-- Attachment #1: Type: text/plain, Size: 36 bytes --]

How's the following updated patch?


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Improve-pure-and-side-effect-free-docs.patch --]
[-- Type: text/x-diff, Size: 5953 bytes --]

From 7bbcfcfc201d8a924b9f19abcc9307001b79ec86 Mon Sep 17 00:00:00 2001
From: "Basil L. Contovounesios" <contovob@tcd.ie>
Date: Wed, 17 Apr 2019 16:34:47 +0100
Subject: [PATCH] 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.
---
 doc/lispref/customize.texi |  8 ++++----
 doc/lispref/eval.texi      |  1 +
 doc/lispref/functions.texi |  7 ++++++-
 doc/lispref/internals.texi |  7 +++----
 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 f71dedfd8b..02eefe0f58 100644
--- a/doc/lispref/customize.texi
+++ b/doc/lispref/customize.texi
@@ -950,10 +950,10 @@ Composite Types
 
 @itemize @bullet
 @item
-A predicate---that is, a function of one argument that has no side
-effects, and returns either @code{nil} or non-@code{nil} according to
-the argument.  Using a predicate in the list says that objects for which
-the predicate returns non-@code{nil} are acceptable.
+A predicate---that is, a function of one argument that returns either
+@code{nil} or non-@code{nil} according to the argument.  Using a
+predicate in the list says that objects for which the predicate
+returns non-@code{nil} are acceptable.
 
 @item
 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 db42dfb637..39c5a1ec50 100644
--- a/doc/lispref/eval.texi
+++ b/doc/lispref/eval.texi
@@ -87,6 +87,7 @@ Intro Eval
 (@pxref{Local Variables}).
 
 @cindex side effect
+@anchor{Definition of side effect}
   Evaluating a form may also make changes that persist; these changes
 are called @dfn{side effects}.  An example of a form that produces a
 side effect is @code{(setq foo 1)}.
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi
index 222f863c98..97f7fb9f79 100644
--- a/doc/lispref/functions.texi
+++ b/doc/lispref/functions.texi
@@ -38,11 +38,16 @@ What Is a Function
 @cindex return value
 @cindex value of function
 @cindex argument
+@cindex pure function
   In a general sense, a function is a rule for carrying out a
 computation given input values called @dfn{arguments}.  The result of
 the computation is called the @dfn{value} or @dfn{return value} of the
 function.  The computation can also have side effects, such as lasting
-changes in the values of variables or the contents of data structures.
+changes in the values of variables or the contents of data structures
+(@pxref{Definition of side effect}).  A @dfn{pure function} is a
+function which, in addition to having no side effects, always returns
+the same value for the same combination of arguments, regardless of
+external factors such as machine type or system state.
 
   In most computer languages, every function has a name.  But in Lisp,
 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 fc5ce594e6..25892d4b57 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -1031,10 +1031,9 @@ Writing Emacs Primitives
 @file{lisp.h} contains the definitions for some important macros and
 functions.
 
-  If you define a function which is side-effect free, update the code
-in @file{byte-opt.el} that binds @code{side-effect-free-fns} and
-@code{side-effect-and-error-free-fns} so that the compiler optimizer
-knows about it.
+  If you define a function which is side-effect free or pure, give it
+a non-@code{nil} @code{side-effect-free} or @code{pure} property,
+respectively (@pxref{Standard Properties}).
 
 @node Writing Dynamic Modules
 @section Writing Dynamically-Loaded Modules
diff --git a/doc/lispref/symbols.texi b/doc/lispref/symbols.texi
index a214a2d3fd..5d71fb39a2 100644
--- a/doc/lispref/symbols.texi
+++ b/doc/lispref/symbols.texi
@@ -558,9 +558,12 @@ Standard Properties
 modes.  @xref{Setting Hooks}.
 
 @item pure
+@cindex @code{pure} property
 If the value is non-@code{nil}, the named function is considered to be
-side-effect free.  Calls with constant arguments can be evaluated at
-compile time.  This may shift run time errors to compile time.
+pure (@pxref{What Is a Function}).  Calls with constant arguments can
+be evaluated at compile time.  This may shift run time errors to
+compile time.  Not to be confused with pure storage (@pxref{Pure
+Storage}).
 
 @item risky-local-variable
 If the value is non-@code{nil}, the named variable is considered risky
@@ -579,9 +582,13 @@ Standard Properties
 for the named variable.  @xref{File Local Variables}.
 
 @item side-effect-free
+@cindex @code{side-effect-free} property
 A non-@code{nil} value indicates that the named function is free of
-side-effects, for determining function safety (@pxref{Function
-Safety}) as well as for byte compiler optimizations.  Do not set it.
+side effects (@pxref{What Is a Function}), so the byte compiler may
+ignore a call whose value is unused.  If the property's value is
+@code{error-free}, the byte compiler may even delete such unused
+calls.  In addition to byte compiler optimizations, this property is
+also used for determining function safety (@pxref{Function Safety}).
 
 @item variable-documentation
 If non-@code{nil}, this specifies the named variable's documentation
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 20 bytes --]


Thanks,

-- 
Basil

  reply	other threads:[~2019-04-21 21:37 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-16 19:34 Predicate for true lists Basil L. Contovounesios
2018-06-04 12:12 ` Basil L. Contovounesios
2018-06-04 14:08   ` Stefan Monnier
2018-06-04 14:46     ` Basil L. Contovounesios
2018-06-04 15:31       ` Drew Adams
2018-06-04 16:14         ` Basil L. Contovounesios
2018-06-04 16:38           ` Drew Adams
2018-06-04 16:57             ` Stefan Monnier
2018-06-05  1:23   ` Paul Eggert
2018-06-05  2:57     ` Drew Adams
2018-06-05  3:08       ` Drew Adams
2018-06-05  3:12         ` Drew Adams
2018-06-05  3:25       ` Drew Adams
2018-06-05 15:05     ` Basil L. Contovounesios
2018-06-06  7:42       ` Paul Eggert
2018-06-06  9:40         ` Van L
2018-06-06 13:44           ` Stefan Monnier
2018-06-06 17:40             ` Stefan Monnier
2018-06-07  7:03             ` Van L
2018-07-05 22:31         ` Basil L. Contovounesios
2018-07-06  5:57           ` Eli Zaretskii
2018-07-06 17:16             ` Drew Adams
2018-07-06 17:38               ` Eli Zaretskii
     [not found]               ` <<83601sl0wo.fsf@gnu.org>
2018-07-06 18:00                 ` Drew Adams
2018-07-07  6:54                   ` Eli Zaretskii
     [not found]               ` <<<83601sl0wo.fsf@gnu.org>
     [not found]                 ` <<95fda70b-5893-4788-83c5-a0bb5d708304@default>
     [not found]                   ` <<8336wvleml.fsf@gnu.org>
2018-07-07 14:42                     ` Drew Adams
2018-07-06 18:04             ` Paul Eggert
2018-07-07  6:58               ` Eli Zaretskii
2018-07-07  7:20                 ` martin rudalics
2018-07-07  8:41                 ` Paul Eggert
2018-07-07 10:04                   ` Eli Zaretskii
2018-07-07 15:04                     ` Basil L. Contovounesios
2018-07-07 16:12                       ` Eli Zaretskii
2018-07-07 16:52                         ` Basil L. Contovounesios
2018-07-07 17:07                           ` Eli Zaretskii
2018-07-07 17:14                             ` Paul Eggert
2018-07-07 17:34                               ` Eli Zaretskii
2018-07-08  0:15                               ` Drew Adams
2018-07-08  4:48                                 ` Paul Eggert
2018-07-08 15:15                                   ` Drew Adams
2018-07-08 16:00                                     ` Paul Eggert
2018-07-08 17:42                                       ` Drew Adams
2018-07-08 17:47                                         ` Paul Eggert
2018-07-07 17:06                     ` Basil L. Contovounesios
2018-07-09 19:25             ` Basil L. Contovounesios
2018-07-09 19:40               ` Basil L. Contovounesios
2018-07-10  2:02                 ` Paul Eggert
2018-07-10  5:46                   ` Basil L. Contovounesios
2018-07-11  3:02                     ` Paul Eggert
2018-07-11  6:27                       ` Basil L. Contovounesios
2018-07-15 22:55                         ` Wilfred Hughes
2018-07-16  1:37                           ` Paul Eggert
2018-07-11 14:01                       ` [Emacs-diffs] master babe0d4: Rearrange definition of zerop in subr.el Karl Fogel
2018-07-11 17:12                         ` Basil L. Contovounesios
2018-07-11 17:33                           ` Paul Eggert
2018-07-12 15:34                             ` Basil L. Contovounesios
2018-07-12 15:43                               ` Basil L. Contovounesios
2019-04-09 12:51                       ` Predicate for true lists Basil L. Contovounesios
2019-04-09 15:33                         ` Stefan Monnier
2019-04-09 16:20                           ` Basil L. Contovounesios
2019-04-09 16:32                             ` Stefan Monnier
2019-04-09 16:54                               ` Daniel Colascione
2019-04-09 17:27                                 ` Basil L. Contovounesios
2019-04-09 17:27                               ` Basil L. Contovounesios
2019-04-09 20:08                               ` Unused value of error-free function warning (was: Predicate for true lists) Basil L. Contovounesios
2019-04-09 20:40                                 ` Unused value of error-free function warning Stefan Monnier
2019-04-09 20:12                           ` Predicate for true lists Basil L. Contovounesios
2019-04-09 20:41                             ` Stefan Monnier
2019-04-10  2:32                             ` Eli Zaretskii
2019-04-10 14:16                               ` Alex Branham
2019-04-10 14:34                                 ` Basil L. Contovounesios
2019-04-10 15:01                                   ` Drew Adams
2019-04-10 15:45                                     ` Basil L. Contovounesios
2019-04-10 16:04                                       ` Eli Zaretskii
2019-04-17 17:56                                       ` Basil L. Contovounesios
2019-04-17 18:11                                         ` Stefan Monnier
2019-04-21 21:42                                           ` Basil L. Contovounesios
2019-04-17 18:55                                         ` Drew Adams
2019-04-21 21:24                                           ` Basil L. Contovounesios
2019-04-22  0:03                                             ` Drew Adams
2019-04-22  1:12                                               ` Michael Heerdegen
2019-04-22  9:39                                                 ` Drew Adams
2019-04-18 14:37                                         ` Eli Zaretskii
2019-04-21 18:30                                           ` Basil L. Contovounesios
2019-04-21 19:39                                             ` Eli Zaretskii
2019-04-21 21:37                                               ` Basil L. Contovounesios [this message]
2019-04-22  0:06                                                 ` Drew Adams
2019-04-22  7:49                                                 ` Eli Zaretskii
2019-04-22 12:59                                                   ` Basil L. Contovounesios
2019-04-22 13:12                                                     ` Eli Zaretskii
2019-04-22 15:19                                                       ` Basil L. Contovounesios
2019-04-21 19:41                                             ` Eli Zaretskii
2019-04-21 21:41                                               ` Basil L. Contovounesios
2019-04-22  6:39                                                 ` Eli Zaretskii
2019-04-22 12:58                                                   ` Basil L. Contovounesios
2018-07-06 17:00           ` Drew Adams
2018-07-06 17:20             ` Paul Eggert
2018-07-06 17:33             ` Eli Zaretskii
2018-07-08 22:38             ` Basil L. Contovounesios
2018-07-06 17:30           ` Paul Eggert
     [not found] <<<87fu3vdjjk.fsf@tcd.ie>
     [not found] <<87fu3vdjjk.fsf@tcd.ie>

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r29v6nw5.fsf@tcd.ie \
    --to=contovob@tcd.ie \
    --cc=branham@utexas.edu \
    --cc=drew.adams@oracle.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).