aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/objects.texi
diff options
context:
space:
mode:
authorGlenn Morris2020-04-20 07:50:19 -0700
committerGlenn Morris2020-04-20 07:50:19 -0700
commit477b9eaf45da1ebc4f2117d69df3571f0bf61e47 (patch)
tree4600314923713c339c41cd450f50e64c3f16a8aa /doc/lispref/objects.texi
parent80f04b5d7c817977a365a999693443c4e04e5223 (diff)
parent05089a4d65831c5e873956f5f2d92a3d5672d405 (diff)
downloademacs-477b9eaf45da1ebc4f2117d69df3571f0bf61e47.tar.gz
emacs-477b9eaf45da1ebc4f2117d69df3571f0bf61e47.zip
Merge from origin/emacs-27
05089a4d65 (origin/emacs-27) Tweak wording re constant variables a1040861f1 Tweak setcar-related wording 751510f865 * lisp/image-mode.el: Add prefix key 's' and reduce depend... 9261a219ec * doc/emacs/windows.texi (Window Convenience): Decribe mor... e1d42da0d6 Fix mutability glitches reported by Drew Adams 5805df74f5 Improve mutability doc dca35b31d0 Improve mutability documentation 81e7d7f111 Document that quoting yields constants 5734339f40 * doc/lispref/keymaps.texi (Extended Menu Items, Easy Menu... 14a570afae Remove #' and function quoting from lambda forms in manual d5ec18c66b * src/regex-emacs.c (re_match_2_internal): Rework comment ... 4df8a61117 Add new node "Image Mode" to Emacs Manual. d7d5ee6c57 ; Fix a typo in cmdargs.texi (bug#40701) 5e9db48fbe * doc/lispref/display.texi (Customizing Bitmaps): Fix typo. eebfb72c90 Document constant vs mutable objects better 6c187ed6b0 Improve documentation of 'sort-lines' 52288f4b66 Mention 'spam-stat-process-directory-age' in the documenta... 067b070598 ; Fix some typos and doc issues (bug#40695) # Conflicts: # etc/NEWS
Diffstat (limited to 'doc/lispref/objects.texi')
-rw-r--r--doc/lispref/objects.texi48
1 files changed, 48 insertions, 0 deletions
diff --git a/doc/lispref/objects.texi b/doc/lispref/objects.texi
index 855dff2130a..3e9f2221020 100644
--- a/doc/lispref/objects.texi
+++ b/doc/lispref/objects.texi
@@ -46,6 +46,10 @@ 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.
50Others are @dfn{mutable}: their values can be changed via destructive
51operations that involve side effects.
52
49 This chapter describes the purpose, printed representation, and read 53 This chapter describes the purpose, printed representation, and read
50syntax of each of the standard types in GNU Emacs Lisp. Details on how 54syntax of each of the standard types in GNU Emacs Lisp. Details on how
51to use these types can be found in later chapters. 55to use these types can be found in later chapters.
@@ -59,6 +63,7 @@ to use these types can be found in later chapters.
59* Circular Objects:: Read syntax for circular structure. 63* Circular Objects:: Read syntax for circular structure.
60* Type Predicates:: Tests related to types. 64* Type Predicates:: Tests related to types.
61* Equality Predicates:: Tests of equality between any two objects. 65* Equality Predicates:: Tests of equality between any two objects.
66* Constants and Mutability:: Whether an object's value can change.
62@end menu 67@end menu
63 68
64@node Printed Representation 69@node Printed Representation
@@ -2377,3 +2382,46 @@ that for two strings to be equal, they have the same text properties.
2377@end group 2382@end group
2378@end example 2383@end example
2379@end defun 2384@end defun
2385
2386@node Constants and Mutability
2387@section Constants and Mutability
2388@cindex constants
2389@cindex mutable objects
2390
2391 Some Lisp objects are constant: their values never change.
2392For example, you can create a new integer by calculating one, but you
2393cannot modify the value of an existing integer.
2394
2395 Other Lisp objects are mutable: their values can be changed
2396via destructive operations involving side effects. For example, an
2397existing marker can be changed by moving the marker to point to
2398somewhere else.
2399
2400 Although numbers are always constants and markers are always
2401mutable, some types contain both constant and mutable members. These
2402types include conses, vectors, strings, and symbols. For example, the string
2403literal @code{"aaa"} yields a constant string, whereas the function
2404call @code{(make-string 3 ?a)} yields a mutable string that can be
2405changed via later calls to @code{aset}.
2406
2407 Trying to modify a constant variable signals an error
2408(@pxref{Constant Variables}).
2409A program should not attempt to modify other types of constants because the
2410resulting behavior is undefined: the Lisp interpreter might or might
2411not detect the error, and if it does not detect the error the
2412interpreter can behave unpredictably thereafter. Another way to put
2413this is that although mutable objects are safe to change and constant
2414symbols reliably reject attempts to change them, other constants are
2415not safely mutable: if you try to change one your program might
2416behave as you expect but it might crash or worse. This problem occurs
2417with types that have both constant and mutable members, and that have
2418mutators like @code{setcar} and @code{aset} that are valid on mutable
2419objects but hazardous on constants.
2420
2421 When the same constant occurs multiple times in a program, the Lisp
2422interpreter might save time or space by reusing existing constants or
2423constant components. For example, @code{(eq "abc" "abc")} returns
2424@code{t} if the interpreter creates only one instance of the string
2425constant @code{"abc"}, and returns @code{nil} if it creates two
2426instances. Lisp programs should be written so that they work
2427regardless of whether this optimization is in use.