aboutsummaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorPaul Eggert2020-04-22 10:42:09 -0700
committerPaul Eggert2020-04-22 10:43:46 -0700
commit400ff5cd195e81204edd9c69fa1b8bc3cb66b42d (patch)
tree4fcc5d46acfb6a465e8fd7a37d7a1d0447ced8ae /doc
parentd2836fe71b30dedb39a8d6e1b1705cece30dcf63 (diff)
downloademacs-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.texi6
-rw-r--r--doc/lispref/lists.texi7
-rw-r--r--doc/lispref/objects.texi21
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)}
610both yield lists equal to @code{(+ 1 2)}, the former yields a
611freshly-minted mutable list whereas the latter yields a constant list
612built 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
610Functions}), which causes an anonymous lambda expression written in Lisp 616Functions}), which causes an anonymous lambda expression written in Lisp
611to be compiled, and @samp{`} (@pxref{Backquote}), which is used to quote 617to 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
46Lisp variables can only take on values of a certain type. 46Lisp 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.
50Others are @dfn{mutable}: their values can be changed via destructive 50Others are @dfn{mutable}: their values can be changed via destructive
51operations that involve side effects. 51operations 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
2388during a single execution of Emacs running well-behaved Lisp code.
2388For example, you can create a new integer by calculating one, but you 2389For example, you can create a new integer by calculating one, but you
2389cannot modify the value of an existing integer. 2390cannot 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
2392via destructive operations involving side effects. For example, an 2393via destructive operations involving side effects. For example, an
2393existing marker can be changed by moving the marker to point to 2394existing marker can be changed by moving the marker to point to
2394somewhere else. 2395somewhere else.
2395 2396
2396 Although numbers are always constants and markers are always 2397 Although all numbers are constants and all markers are
2397mutable, some types contain both constant and mutable members. These 2398mutable, some types contain both constant and mutable members. These
2398types include conses, vectors, strings, and symbols. For example, the string 2399types include conses, vectors, strings, and symbols. For example, the string
2399literal @code{"aaa"} yields a constant string, whereas the function 2400literal @code{"aaa"} yields a constant string, whereas the function
2400call @code{(make-string 3 ?a)} yields a mutable string that can be 2401call @code{(make-string 3 ?a)} yields a mutable string that can be
2401changed via later calls to @code{aset}. 2402changed 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
2406that is being evaluated. The reverse does not occur: constant objects
2407should 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}).
2405A program should not attempt to modify other types of constants because the 2411A 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
2407not detect the error, and if it does not detect the error the 2413not detect the error, and if it does not detect the error the
2408interpreter can behave unpredictably thereafter. Another way to put 2414interpreter can behave unpredictably thereafter. Another way to put
2409this is that although mutable objects are safe to change and constant 2415this is that although mutable objects are safe to change and constant
2410symbols reliably reject attempts to change them, other constants are 2416variables reliably prevent attempts to change them, other constants
2411not safely mutable: if you try to change one your program might 2417are not safely mutable: if a misbehaving program tries to change such a
2412behave as you expect but it might crash or worse. This problem occurs 2418constant then the constant's value might actually change, or the
2419program might crash or worse. This problem occurs
2413with types that have both constant and mutable members, and that have 2420with types that have both constant and mutable members, and that have
2414mutators like @code{setcar} and @code{aset} that are valid on mutable 2421mutators like @code{setcar} and @code{aset} that are valid on mutable
2415objects but hazardous on constants. 2422objects but hazardous on constants.