diff options
| author | Paul Eggert | 2020-04-22 10:42:09 -0700 |
|---|---|---|
| committer | Paul Eggert | 2020-04-22 10:43:46 -0700 |
| commit | 400ff5cd195e81204edd9c69fa1b8bc3cb66b42d (patch) | |
| tree | 4fcc5d46acfb6a465e8fd7a37d7a1d0447ced8ae /doc | |
| parent | d2836fe71b30dedb39a8d6e1b1705cece30dcf63 (diff) | |
| download | emacs-400ff5cd195e81204edd9c69fa1b8bc3cb66b42d.tar.gz emacs-400ff5cd195e81204edd9c69fa1b8bc3cb66b42d.zip | |
Improve wording about constants
Thanks to Štěpán Němec and Drew Adams for reviews of recent changes.
* doc/lispref/eval.texi (Quoting): Give an example.
* doc/lispref/lists.texi (Association Lists): Simplify example code.
* doc/lispref/objects.texi (Lisp Data Types)
(Constants and Mutability): Clarify wording.
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/lispref/eval.texi | 6 | ||||
| -rw-r--r-- | doc/lispref/lists.texi | 7 | ||||
| -rw-r--r-- | doc/lispref/objects.texi | 21 |
3 files changed, 23 insertions, 11 deletions
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index 021604c5142..baddce4d9c9 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -606,6 +606,12 @@ Here are some examples of expressions that use @code{quote}: | |||
| 606 | @end group | 606 | @end group |
| 607 | @end example | 607 | @end example |
| 608 | 608 | ||
| 609 | Although the expressions @code{(list '+ 1 2)} and @code{'(+ 1 2)} | ||
| 610 | both yield lists equal to @code{(+ 1 2)}, the former yields a | ||
| 611 | freshly-minted mutable list whereas the latter yields a constant list | ||
| 612 | built from conses that may be shared with other constants. | ||
| 613 | @xref{Constants and Mutability}. | ||
| 614 | |||
| 609 | Other quoting constructs include @code{function} (@pxref{Anonymous | 615 | Other quoting constructs include @code{function} (@pxref{Anonymous |
| 610 | Functions}), which causes an anonymous lambda expression written in Lisp | 616 | Functions}), which causes an anonymous lambda expression written in Lisp |
| 611 | to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote | 617 | to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote |
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 1125af7bec3..ea44e01f48a 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -1625,10 +1625,9 @@ keys may not be symbols: | |||
| 1625 | '(("simple leaves" . oak) | 1625 | '(("simple leaves" . oak) |
| 1626 | ("compound leaves" . horsechestnut))) | 1626 | ("compound leaves" . horsechestnut))) |
| 1627 | 1627 | ||
| 1628 | ;; @r{The @code{copy-sequence} means the keys are not @code{eq}.} | 1628 | (assq "simple leaves" leaves) |
| 1629 | (assq (copy-sequence "simple leaves") leaves) | 1629 | @result{} @r{Unspecified; might be @code{nil} or non-@code{nil}.} |
| 1630 | @result{} nil | 1630 | (assoc "simple leaves" leaves) |
| 1631 | (assoc (copy-sequence "simple leaves") leaves) | ||
| 1632 | @result{} ("simple leaves" . oak) | 1631 | @result{} ("simple leaves" . oak) |
| 1633 | @end smallexample | 1632 | @end smallexample |
| 1634 | @end defun | 1633 | @end defun |
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi index abd258eb537..1eda94ab63e 100644 --- a/doc/lispref/objects.texi +++ b/doc/lispref/objects.texi | |||
| @@ -46,7 +46,7 @@ you store in it, type and all. (Actually, a small number of Emacs | |||
| 46 | Lisp variables can only take on values of a certain type. | 46 | Lisp variables can only take on values of a certain type. |
| 47 | @xref{Variables with Restricted Values}.) | 47 | @xref{Variables with Restricted Values}.) |
| 48 | 48 | ||
| 49 | Some Lisp objects are @dfn{constant}: their values never change. | 49 | Some Lisp objects are @dfn{constant}: their values should never change. |
| 50 | Others are @dfn{mutable}: their values can be changed via destructive | 50 | Others are @dfn{mutable}: their values can be changed via destructive |
| 51 | operations that involve side effects. | 51 | operations that involve side effects. |
| 52 | 52 | ||
| @@ -2384,22 +2384,28 @@ that for two strings to be equal, they have the same text properties. | |||
| 2384 | @cindex constants | 2384 | @cindex constants |
| 2385 | @cindex mutable objects | 2385 | @cindex mutable objects |
| 2386 | 2386 | ||
| 2387 | Some Lisp objects are constant: their values never change. | 2387 | Some Lisp objects are constant: their values should never change |
| 2388 | during a single execution of Emacs running well-behaved Lisp code. | ||
| 2388 | For example, you can create a new integer by calculating one, but you | 2389 | For example, you can create a new integer by calculating one, but you |
| 2389 | cannot modify the value of an existing integer. | 2390 | cannot modify the value of an existing integer. |
| 2390 | 2391 | ||
| 2391 | Other Lisp objects are mutable: their values can be changed | 2392 | Other Lisp objects are mutable: it is safe to change their values |
| 2392 | via destructive operations involving side effects. For example, an | 2393 | via destructive operations involving side effects. For example, an |
| 2393 | existing marker can be changed by moving the marker to point to | 2394 | existing marker can be changed by moving the marker to point to |
| 2394 | somewhere else. | 2395 | somewhere else. |
| 2395 | 2396 | ||
| 2396 | Although numbers are always constants and markers are always | 2397 | Although all numbers are constants and all markers are |
| 2397 | mutable, some types contain both constant and mutable members. These | 2398 | mutable, some types contain both constant and mutable members. These |
| 2398 | types include conses, vectors, strings, and symbols. For example, the string | 2399 | types include conses, vectors, strings, and symbols. For example, the string |
| 2399 | literal @code{"aaa"} yields a constant string, whereas the function | 2400 | literal @code{"aaa"} yields a constant string, whereas the function |
| 2400 | call @code{(make-string 3 ?a)} yields a mutable string that can be | 2401 | call @code{(make-string 3 ?a)} yields a mutable string that can be |
| 2401 | changed via later calls to @code{aset}. | 2402 | changed via later calls to @code{aset}. |
| 2402 | 2403 | ||
| 2404 | A mutable object can become constant if it is passed to the | ||
| 2405 | @code{eval} function, because a program should not modify an object | ||
| 2406 | that is being evaluated. The reverse does not occur: constant objects | ||
| 2407 | should stay constant. | ||
| 2408 | |||
| 2403 | Trying to modify a constant variable signals an error | 2409 | Trying to modify a constant variable signals an error |
| 2404 | (@pxref{Constant Variables}). | 2410 | (@pxref{Constant Variables}). |
| 2405 | A program should not attempt to modify other types of constants because the | 2411 | A program should not attempt to modify other types of constants because the |
| @@ -2407,9 +2413,10 @@ resulting behavior is undefined: the Lisp interpreter might or might | |||
| 2407 | not detect the error, and if it does not detect the error the | 2413 | not detect the error, and if it does not detect the error the |
| 2408 | interpreter can behave unpredictably thereafter. Another way to put | 2414 | interpreter can behave unpredictably thereafter. Another way to put |
| 2409 | this is that although mutable objects are safe to change and constant | 2415 | this is that although mutable objects are safe to change and constant |
| 2410 | symbols reliably reject attempts to change them, other constants are | 2416 | variables reliably prevent attempts to change them, other constants |
| 2411 | not safely mutable: if you try to change one your program might | 2417 | are not safely mutable: if a misbehaving program tries to change such a |
| 2412 | behave as you expect but it might crash or worse. This problem occurs | 2418 | constant then the constant's value might actually change, or the |
| 2419 | program might crash or worse. This problem occurs | ||
| 2413 | with types that have both constant and mutable members, and that have | 2420 | with types that have both constant and mutable members, and that have |
| 2414 | mutators like @code{setcar} and @code{aset} that are valid on mutable | 2421 | mutators like @code{setcar} and @code{aset} that are valid on mutable |
| 2415 | objects but hazardous on constants. | 2422 | objects but hazardous on constants. |