diff options
| author | Glenn Morris | 2020-04-20 07:50:19 -0700 |
|---|---|---|
| committer | Glenn Morris | 2020-04-20 07:50:19 -0700 |
| commit | 477b9eaf45da1ebc4f2117d69df3571f0bf61e47 (patch) | |
| tree | 4600314923713c339c41cd450f50e64c3f16a8aa /doc/lispref | |
| parent | 80f04b5d7c817977a365a999693443c4e04e5223 (diff) | |
| parent | 05089a4d65831c5e873956f5f2d92a3d5672d405 (diff) | |
| download | emacs-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')
| -rw-r--r-- | doc/lispref/abbrevs.texi | 6 | ||||
| -rw-r--r-- | doc/lispref/backups.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/display.texi | 6 | ||||
| -rw-r--r-- | doc/lispref/edebug.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/elisp.texi | 1 | ||||
| -rw-r--r-- | doc/lispref/eval.texi | 15 | ||||
| -rw-r--r-- | doc/lispref/functions.texi | 4 | ||||
| -rw-r--r-- | doc/lispref/help.texi | 56 | ||||
| -rw-r--r-- | doc/lispref/keymaps.texi | 33 | ||||
| -rw-r--r-- | doc/lispref/lists.texi | 68 | ||||
| -rw-r--r-- | doc/lispref/objects.texi | 48 | ||||
| -rw-r--r-- | doc/lispref/os.texi | 2 | ||||
| -rw-r--r-- | doc/lispref/sequences.texi | 51 | ||||
| -rw-r--r-- | doc/lispref/strings.texi | 18 | ||||
| -rw-r--r-- | doc/lispref/syntax.texi | 6 | ||||
| -rw-r--r-- | doc/lispref/text.texi | 13 |
16 files changed, 205 insertions, 126 deletions
diff --git a/doc/lispref/abbrevs.texi b/doc/lispref/abbrevs.texi index 6689b560c78..575be187d3f 100644 --- a/doc/lispref/abbrevs.texi +++ b/doc/lispref/abbrevs.texi | |||
| @@ -370,9 +370,9 @@ definitions of @code{local-abbrev-table} and @code{text-mode-abbrev-table}. | |||
| 370 | (funcall expand)))) | 370 | (funcall expand)))) |
| 371 | 371 | ||
| 372 | (add-hook 'foo-mode-hook | 372 | (add-hook 'foo-mode-hook |
| 373 | #'(lambda () | 373 | (lambda () |
| 374 | (add-function :around (local 'abbrev-expand-function) | 374 | (add-function :around (local 'abbrev-expand-function) |
| 375 | #'foo-mode-abbrev-expand-function))) | 375 | #'foo-mode-abbrev-expand-function))) |
| 376 | @end smallexample | 376 | @end smallexample |
| 377 | 377 | ||
| 378 | @node Standard Abbrev Tables | 378 | @node Standard Abbrev Tables |
diff --git a/doc/lispref/backups.texi b/doc/lispref/backups.texi index b7318a99b8f..4ed1a10fcf6 100644 --- a/doc/lispref/backups.texi +++ b/doc/lispref/backups.texi | |||
| @@ -807,7 +807,7 @@ If you just want to automatically auto-revert every | |||
| 807 | 807 | ||
| 808 | @example | 808 | @example |
| 809 | (setq-local buffer-stale-function | 809 | (setq-local buffer-stale-function |
| 810 | #'(lambda (&optional noconfirm) 'fast)) | 810 | (lambda (&optional noconfirm) 'fast)) |
| 811 | @end example | 811 | @end example |
| 812 | 812 | ||
| 813 | @noindent | 813 | @noindent |
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 132a3c85354..e01cfedc4b8 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi | |||
| @@ -4358,7 +4358,7 @@ height. | |||
| 4358 | @end defun | 4358 | @end defun |
| 4359 | 4359 | ||
| 4360 | @defun destroy-fringe-bitmap bitmap | 4360 | @defun destroy-fringe-bitmap bitmap |
| 4361 | This function destroy the fringe bitmap identified by @var{bitmap}. | 4361 | This function destroys the fringe bitmap identified by @var{bitmap}. |
| 4362 | If @var{bitmap} identifies a standard fringe bitmap, it actually | 4362 | If @var{bitmap} identifies a standard fringe bitmap, it actually |
| 4363 | restores the standard definition of that bitmap, instead of | 4363 | restores the standard definition of that bitmap, instead of |
| 4364 | eliminating it entirely. | 4364 | eliminating it entirely. |
| @@ -6926,7 +6926,7 @@ end of the buffer continues from the other end. If | |||
| 6926 | is displayed. Any button with a non-@code{nil} @code{skip} property | 6926 | is displayed. Any button with a non-@code{nil} @code{skip} property |
| 6927 | is skipped over. Returns the button found, and signals an error if no | 6927 | is skipped over. Returns the button found, and signals an error if no |
| 6928 | buttons can be found. If @var{no-error} in non-@code{nil}, return nil | 6928 | buttons can be found. If @var{no-error} in non-@code{nil}, return nil |
| 6929 | instead of signalling the error. | 6929 | instead of signaling the error. |
| 6930 | @end deffn | 6930 | @end deffn |
| 6931 | 6931 | ||
| 6932 | @deffn Command backward-button n &optional wrap display-message | 6932 | @deffn Command backward-button n &optional wrap display-message |
| @@ -6938,7 +6938,7 @@ end of the buffer continues from the other end. If | |||
| 6938 | is displayed. Any button with a non-@code{nil} @code{skip} property | 6938 | is displayed. Any button with a non-@code{nil} @code{skip} property |
| 6939 | is skipped over. Returns the button found, and signals an error if no | 6939 | is skipped over. Returns the button found, and signals an error if no |
| 6940 | buttons can be found. If @var{no-error} in non-@code{nil}, return nil | 6940 | buttons can be found. If @var{no-error} in non-@code{nil}, return nil |
| 6941 | instead of signalling the error. | 6941 | instead of signaling the error. |
| 6942 | @end deffn | 6942 | @end deffn |
| 6943 | 6943 | ||
| 6944 | @defun next-button pos &optional count-current | 6944 | @defun next-button pos &optional count-current |
diff --git a/doc/lispref/edebug.texi b/doc/lispref/edebug.texi index cfef5c12d1e..5970e7cf801 100644 --- a/doc/lispref/edebug.texi +++ b/doc/lispref/edebug.texi | |||
| @@ -858,7 +858,7 @@ to a non-@code{nil} value. | |||
| 858 | Here is an example of code that creates a circular structure: | 858 | Here is an example of code that creates a circular structure: |
| 859 | 859 | ||
| 860 | @example | 860 | @example |
| 861 | (setq a '(x y)) | 861 | (setq a (list 'x 'y)) |
| 862 | (setcar a a) | 862 | (setcar a a) |
| 863 | @end example | 863 | @end example |
| 864 | 864 | ||
diff --git a/doc/lispref/elisp.texi b/doc/lispref/elisp.texi index cfd96f7aa68..bba1b63115f 100644 --- a/doc/lispref/elisp.texi +++ b/doc/lispref/elisp.texi | |||
| @@ -297,6 +297,7 @@ Lisp Data Types | |||
| 297 | * Circular Objects:: Read syntax for circular structure. | 297 | * Circular Objects:: Read syntax for circular structure. |
| 298 | * Type Predicates:: Tests related to types. | 298 | * Type Predicates:: Tests related to types. |
| 299 | * Equality Predicates:: Tests of equality between any two objects. | 299 | * Equality Predicates:: Tests of equality between any two objects. |
| 300 | * Constants and Mutability:: Whether an object's value can change. | ||
| 300 | 301 | ||
| 301 | Programming Types | 302 | Programming Types |
| 302 | 303 | ||
diff --git a/doc/lispref/eval.texi b/doc/lispref/eval.texi index f6f36ed3427..021604c5142 100644 --- a/doc/lispref/eval.texi +++ b/doc/lispref/eval.texi | |||
| @@ -158,6 +158,12 @@ contents unchanged. | |||
| 158 | @end group | 158 | @end group |
| 159 | @end example | 159 | @end example |
| 160 | 160 | ||
| 161 | A self-evaluating form yields constant conses, vectors and strings, and you | ||
| 162 | should not attempt to modify their contents via @code{setcar}, @code{aset} or | ||
| 163 | similar operations. The Lisp interpreter might unify the constants | ||
| 164 | yielded by your program's self-evaluating forms, so that these | ||
| 165 | constants might share structure. @xref{Constants and Mutability}. | ||
| 166 | |||
| 161 | It is common to write numbers, characters, strings, and even vectors | 167 | It is common to write numbers, characters, strings, and even vectors |
| 162 | in Lisp code, taking advantage of the fact that they self-evaluate. | 168 | in Lisp code, taking advantage of the fact that they self-evaluate. |
| 163 | However, it is quite unusual to do this for types that lack a read | 169 | However, it is quite unusual to do this for types that lack a read |
| @@ -558,6 +564,8 @@ and vectors.) | |||
| 558 | 564 | ||
| 559 | @defspec quote object | 565 | @defspec quote object |
| 560 | This special form returns @var{object}, without evaluating it. | 566 | This special form returns @var{object}, without evaluating it. |
| 567 | The returned value is a constant, and should not be modified. | ||
| 568 | @xref{Constants and Mutability}. | ||
| 561 | @end defspec | 569 | @end defspec |
| 562 | 570 | ||
| 563 | @cindex @samp{'} for quoting | 571 | @cindex @samp{'} for quoting |
| @@ -612,10 +620,12 @@ only part of a list, while computing and substituting other parts. | |||
| 612 | 620 | ||
| 613 | @dfn{Backquote constructs} allow you to quote a list, but | 621 | @dfn{Backquote constructs} allow you to quote a list, but |
| 614 | selectively evaluate elements of that list. In the simplest case, it | 622 | selectively evaluate elements of that list. In the simplest case, it |
| 615 | is identical to the special form @code{quote} | 623 | is identical to the special form |
| 616 | @iftex | 624 | @iftex |
| 625 | @code{quote}. | ||
| 617 | @end iftex | 626 | @end iftex |
| 618 | @ifnottex | 627 | @ifnottex |
| 628 | @code{quote} | ||
| 619 | (described in the previous section; @pxref{Quoting}). | 629 | (described in the previous section; @pxref{Quoting}). |
| 620 | @end ifnottex | 630 | @end ifnottex |
| 621 | For example, these two forms yield identical results: | 631 | For example, these two forms yield identical results: |
| @@ -693,6 +703,9 @@ Here are some examples: | |||
| 693 | @end group | 703 | @end group |
| 694 | @end example | 704 | @end example |
| 695 | 705 | ||
| 706 | If a subexpression of a backquote construct has no substitutions or | ||
| 707 | splices, it acts like @code{quote} in that it yields constant conses, | ||
| 708 | vectors and strings that should not be modified. | ||
| 696 | 709 | ||
| 697 | @node Eval | 710 | @node Eval |
| 698 | @section Eval | 711 | @section Eval |
diff --git a/doc/lispref/functions.texi b/doc/lispref/functions.texi index 5cf67ba6473..bc8ec0ef1b0 100644 --- a/doc/lispref/functions.texi +++ b/doc/lispref/functions.texi | |||
| @@ -970,7 +970,7 @@ string. | |||
| 970 | @end group | 970 | @end group |
| 971 | 971 | ||
| 972 | @group | 972 | @group |
| 973 | (mapconcat (function (lambda (x) (format "%c" (1+ x)))) | 973 | (mapconcat (lambda (x) (format "%c" (1+ x))) |
| 974 | "HAL-8000" | 974 | "HAL-8000" |
| 975 | "") | 975 | "") |
| 976 | @result{} "IBM.9111" | 976 | @result{} "IBM.9111" |
| @@ -2287,7 +2287,7 @@ function) as a generalized variable. @var{setter} can be a symbol in which | |||
| 2287 | case it will be passed to @code{gv-define-simple-setter}, or it can be of the | 2287 | case it will be passed to @code{gv-define-simple-setter}, or it can be of the |
| 2288 | form @code{(lambda (@var{arg}) @var{body})} in which case that function will | 2288 | form @code{(lambda (@var{arg}) @var{body})} in which case that function will |
| 2289 | additionally have access to the macro (or function)'s arguments and it will | 2289 | additionally have access to the macro (or function)'s arguments and it will |
| 2290 | passed to @code{gv-define-setter}. | 2290 | be passed to @code{gv-define-setter}. |
| 2291 | 2291 | ||
| 2292 | @end table | 2292 | @end table |
| 2293 | 2293 | ||
diff --git a/doc/lispref/help.texi b/doc/lispref/help.texi index eea1fd2e8f1..9b3c4fcb23d 100644 --- a/doc/lispref/help.texi +++ b/doc/lispref/help.texi | |||
| @@ -175,49 +175,47 @@ All symbols that have PATTERN in their name are described | |||
| 175 | in the *Help* buffer." | 175 | in the *Help* buffer." |
| 176 | (interactive "sDescribe symbols matching: ") | 176 | (interactive "sDescribe symbols matching: ") |
| 177 | (let ((describe-func | 177 | (let ((describe-func |
| 178 | (function | 178 | (lambda (s) |
| 179 | (lambda (s) | ||
| 180 | @end group | 179 | @end group |
| 181 | @group | 180 | @group |
| 182 | ;; @r{Print description of symbol.} | 181 | ;; @r{Print description of symbol.} |
| 183 | (if (fboundp s) ; @r{It is a function.} | 182 | (if (fboundp s) ; @r{It is a function.} |
| 184 | (princ | 183 | (princ |
| 185 | (format "%s\t%s\n%s\n\n" s | 184 | (format "%s\t%s\n%s\n\n" s |
| 186 | (if (commandp s) | 185 | (if (commandp s) |
| 187 | (let ((keys (where-is-internal s))) | 186 | (let ((keys (where-is-internal s))) |
| 188 | (if keys | 187 | (if keys |
| 189 | (concat | 188 | (concat |
| 190 | "Keys: " | 189 | "Keys: " |
| 191 | (mapconcat 'key-description | 190 | (mapconcat 'key-description |
| 192 | keys " ")) | 191 | keys " ")) |
| 193 | "Keys: none")) | 192 | "Keys: none")) |
| 194 | "Function") | 193 | "Function") |
| 195 | @end group | 194 | @end group |
| 196 | @group | 195 | @group |
| 197 | (or (documentation s) | 196 | (or (documentation s) |
| 198 | "not documented")))) | 197 | "not documented")))) |
| 199 | 198 | ||
| 200 | (if (boundp s) ; @r{It is a variable.} | 199 | (if (boundp s) ; @r{It is a variable.} |
| 201 | @end group | 200 | @end group |
| 202 | @group | 201 | @group |
| 203 | (princ | 202 | (princ |
| 204 | (format "%s\t%s\n%s\n\n" s | 203 | (format "%s\t%s\n%s\n\n" s |
| 205 | (if (custom-variable-p s) | 204 | (if (custom-variable-p s) |
| 206 | "Option " "Variable") | 205 | "Option " "Variable") |
| 207 | @end group | 206 | @end group |
| 208 | @group | 207 | @group |
| 209 | (or (documentation-property | 208 | (or (documentation-property |
| 210 | s 'variable-documentation) | 209 | s 'variable-documentation) |
| 211 | "not documented"))))))) | 210 | "not documented")))))) |
| 212 | sym-list) | 211 | sym-list) |
| 213 | @end group | 212 | @end group |
| 214 | 213 | ||
| 215 | @group | 214 | @group |
| 216 | ;; @r{Build a list of symbols that match pattern.} | 215 | ;; @r{Build a list of symbols that match pattern.} |
| 217 | (mapatoms (function | 216 | (mapatoms (lambda (sym) |
| 218 | (lambda (sym) | 217 | (if (string-match pattern (symbol-name sym)) |
| 219 | (if (string-match pattern (symbol-name sym)) | 218 | (setq sym-list (cons sym sym-list))))) |
| 220 | (setq sym-list (cons sym sym-list)))))) | ||
| 221 | @end group | 219 | @end group |
| 222 | 220 | ||
| 223 | @group | 221 | @group |
diff --git a/doc/lispref/keymaps.texi b/doc/lispref/keymaps.texi index 2c90d208c02..130ff0d8671 100644 --- a/doc/lispref/keymaps.texi +++ b/doc/lispref/keymaps.texi | |||
| @@ -1441,10 +1441,10 @@ Here is an example showing a keymap before and after substitution: | |||
| 1441 | 1441 | ||
| 1442 | @smallexample | 1442 | @smallexample |
| 1443 | @group | 1443 | @group |
| 1444 | (setq map '(keymap | 1444 | (setq map (list 'keymap |
| 1445 | (?1 . olddef-1) | 1445 | (cons ?1 olddef-1) |
| 1446 | (?2 . olddef-2) | 1446 | (cons ?2 olddef-2) |
| 1447 | (?3 . olddef-1))) | 1447 | (cons ?3 olddef-1))) |
| 1448 | @result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1)) | 1448 | @result{} (keymap (49 . olddef-1) (50 . olddef-2) (51 . olddef-1)) |
| 1449 | @end group | 1449 | @end group |
| 1450 | 1450 | ||
| @@ -2226,14 +2226,11 @@ right value for selecting that button. Clicking on the button should | |||
| 2226 | set the variable so that the button you clicked on becomes selected. | 2226 | set the variable so that the button you clicked on becomes selected. |
| 2227 | 2227 | ||
| 2228 | @item :key-sequence @var{key-sequence} | 2228 | @item :key-sequence @var{key-sequence} |
| 2229 | This property specifies which key sequence is likely to be bound to the | 2229 | This property specifies which key sequence to display as keyboard equivalent. |
| 2230 | same command invoked by this menu item. If you specify a correct key | 2230 | Before Emacs displays @var{key-sequence} in the menu, it verifies that |
| 2231 | sequence, that sequence will be preferred over others. | 2231 | @var{key-sequence} is really equivalent to this menu item, so it only |
| 2232 | 2232 | has an effect if you specify a correct key sequence. | |
| 2233 | If you specify an incorrect key sequence, it has no effect; before Emacs | 2233 | Specifying @code{nil} for @var{key-sequence} is equivalent to the |
| 2234 | displays @var{key-sequence} in the menu, it verifies that | ||
| 2235 | @var{key-sequence} is really equivalent to this menu item. Specifying | ||
| 2236 | @code{nil} for @var{key-sequence} is equivalent to the | ||
| 2237 | @code{:key-sequence} attribute being absent. | 2234 | @code{:key-sequence} attribute being absent. |
| 2238 | 2235 | ||
| 2239 | @item :keys @var{string} | 2236 | @item :keys @var{string} |
| @@ -2916,17 +2913,17 @@ the following: | |||
| 2916 | 2913 | ||
| 2917 | @table @code | 2914 | @table @code |
| 2918 | @item :keys @var{keys} | 2915 | @item :keys @var{keys} |
| 2919 | @var{keys} is a keyboard equivalent to the menu item (a string). This | 2916 | @var{keys} is a string to display as keyboard equivalent to the menu item. |
| 2920 | is normally not needed, as keyboard equivalents are computed | 2917 | This is normally not needed, as keyboard equivalents are computed |
| 2921 | automatically. @var{keys} is expanded with | 2918 | automatically. @var{keys} is expanded with |
| 2922 | @code{substitute-command-keys} before it is displayed (@pxref{Keys in | 2919 | @code{substitute-command-keys} before it is displayed (@pxref{Keys in |
| 2923 | Documentation}). | 2920 | Documentation}). |
| 2924 | 2921 | ||
| 2925 | @item :key-sequence @var{keys} | 2922 | @item :key-sequence @var{keys} |
| 2926 | @var{keys} is a hint for speeding up Emacs's first display of the | 2923 | @var{keys} is a hint indicating which key sequence to display as |
| 2927 | menu. It should be @code{nil} if you know that the menu item has no keyboard | 2924 | keyboard equivalent, in case the command is bound to several key sequences. |
| 2928 | equivalent; otherwise it should be a string or vector specifying a | 2925 | It has no effect if @var{keys} is not bound to same command as this |
| 2929 | keyboard equivalent for the menu item. | 2926 | menu item. |
| 2930 | 2927 | ||
| 2931 | @item :active @var{enable} | 2928 | @item :active @var{enable} |
| 2932 | @var{enable} is an expression; if it evaluates to @code{nil}, the item | 2929 | @var{enable} is an expression; if it evaluates to @code{nil}, the item |
diff --git a/doc/lispref/lists.texi b/doc/lispref/lists.texi index 27fa5385e35..1125af7bec3 100644 --- a/doc/lispref/lists.texi +++ b/doc/lispref/lists.texi | |||
| @@ -866,10 +866,15 @@ foo ;; @r{@code{foo} was changed.} | |||
| 866 | @node Modifying Lists | 866 | @node Modifying Lists |
| 867 | @section Modifying Existing List Structure | 867 | @section Modifying Existing List Structure |
| 868 | @cindex destructive list operations | 868 | @cindex destructive list operations |
| 869 | @cindex mutable lists | ||
| 869 | 870 | ||
| 870 | You can modify the @sc{car} and @sc{cdr} contents of a cons cell with the | 871 | You can modify the @sc{car} and @sc{cdr} contents of a cons cell with the |
| 871 | primitives @code{setcar} and @code{setcdr}. These are destructive | 872 | primitives @code{setcar} and @code{setcdr}. These are destructive |
| 872 | operations because they change existing list structure. | 873 | operations because they change existing list structure. |
| 874 | Destructive operations should be applied only to mutable lists, | ||
| 875 | that is, lists constructed via @code{cons}, @code{list} or similar | ||
| 876 | operations. Lists created by quoting are constants and should not be | ||
| 877 | changed by destructive operations. @xref{Constants and Mutability}. | ||
| 873 | 878 | ||
| 874 | @cindex CL note---@code{rplaca} vs @code{setcar} | 879 | @cindex CL note---@code{rplaca} vs @code{setcar} |
| 875 | @quotation | 880 | @quotation |
| @@ -906,7 +911,7 @@ value @var{object}. For example: | |||
| 906 | 911 | ||
| 907 | @example | 912 | @example |
| 908 | @group | 913 | @group |
| 909 | (setq x '(1 2)) | 914 | (setq x (list 1 2)) ; @r{Create a mutable list.} |
| 910 | @result{} (1 2) | 915 | @result{} (1 2) |
| 911 | @end group | 916 | @end group |
| 912 | @group | 917 | @group |
| @@ -926,8 +931,8 @@ these lists. Here is an example: | |||
| 926 | 931 | ||
| 927 | @example | 932 | @example |
| 928 | @group | 933 | @group |
| 929 | ;; @r{Create two lists that are partly shared.} | 934 | ;; @r{Create two mutable lists that are partly shared.} |
| 930 | (setq x1 '(a b c)) | 935 | (setq x1 (list 'a 'b 'c)) |
| 931 | @result{} (a b c) | 936 | @result{} (a b c) |
| 932 | (setq x2 (cons 'z (cdr x1))) | 937 | (setq x2 (cons 'z (cdr x1))) |
| 933 | @result{} (z b c) | 938 | @result{} (z b c) |
| @@ -1017,11 +1022,11 @@ reached via the @sc{cdr}. | |||
| 1017 | 1022 | ||
| 1018 | @example | 1023 | @example |
| 1019 | @group | 1024 | @group |
| 1020 | (setq x '(1 2 3)) | 1025 | (setq x (list 1 2 3)) ; @r{Create a mutable list.} |
| 1021 | @result{} (1 2 3) | 1026 | @result{} (1 2 3) |
| 1022 | @end group | 1027 | @end group |
| 1023 | @group | 1028 | @group |
| 1024 | (setcdr x '(4)) | 1029 | (setcdr x '(4)) ; @r{Modify the list's tail to be a constant list.} |
| 1025 | @result{} (4) | 1030 | @result{} (4) |
| 1026 | @end group | 1031 | @end group |
| 1027 | @group | 1032 | @group |
| @@ -1037,7 +1042,7 @@ the @sc{cdr} of the first cons cell: | |||
| 1037 | 1042 | ||
| 1038 | @example | 1043 | @example |
| 1039 | @group | 1044 | @group |
| 1040 | (setq x1 '(a b c)) | 1045 | (setq x1 (list 'a 'b 'c)) |
| 1041 | @result{} (a b c) | 1046 | @result{} (a b c) |
| 1042 | (setcdr x1 (cdr (cdr x1))) | 1047 | (setcdr x1 (cdr (cdr x1))) |
| 1043 | @result{} (c) | 1048 | @result{} (c) |
| @@ -1069,7 +1074,7 @@ of this list. | |||
| 1069 | 1074 | ||
| 1070 | @example | 1075 | @example |
| 1071 | @group | 1076 | @group |
| 1072 | (setq x1 '(a b c)) | 1077 | (setq x1 (list 'a 'b 'c)) |
| 1073 | @result{} (a b c) | 1078 | @result{} (a b c) |
| 1074 | (setcdr x1 (cons 'd (cdr x1))) | 1079 | (setcdr x1 (cons 'd (cdr x1))) |
| 1075 | @result{} (d b c) | 1080 | @result{} (d b c) |
| @@ -1130,11 +1135,11 @@ Unlike @code{append} (@pxref{Building Lists}), the @var{lists} are | |||
| 1130 | 1135 | ||
| 1131 | @example | 1136 | @example |
| 1132 | @group | 1137 | @group |
| 1133 | (setq x '(1 2 3)) | 1138 | (setq x (list 1 2 3)) ; @r{Create a mutable list.} |
| 1134 | @result{} (1 2 3) | 1139 | @result{} (1 2 3) |
| 1135 | @end group | 1140 | @end group |
| 1136 | @group | 1141 | @group |
| 1137 | (nconc x '(4 5)) | 1142 | (nconc x '(4 5)) ; @r{Modify the list's tail to be a constant list.} |
| 1138 | @result{} (1 2 3 4 5) | 1143 | @result{} (1 2 3 4 5) |
| 1139 | @end group | 1144 | @end group |
| 1140 | @group | 1145 | @group |
| @@ -1150,7 +1155,7 @@ list: | |||
| 1150 | 1155 | ||
| 1151 | @example | 1156 | @example |
| 1152 | @group | 1157 | @group |
| 1153 | (setq x '(1 2 3)) | 1158 | (setq x (list 1 2 3)) |
| 1154 | @result{} (1 2 3) | 1159 | @result{} (1 2 3) |
| 1155 | @end group | 1160 | @end group |
| 1156 | @group | 1161 | @group |
| @@ -1163,11 +1168,13 @@ x | |||
| 1163 | @end group | 1168 | @end group |
| 1164 | @end example | 1169 | @end example |
| 1165 | 1170 | ||
| 1166 | However, the other arguments (all but the last) must be lists. | 1171 | However, the other arguments (all but the last) should be mutable lists. |
| 1167 | 1172 | ||
| 1168 | A common pitfall is to use a quoted constant list as a non-last | 1173 | A common pitfall is to use a constant list as a non-last |
| 1169 | argument to @code{nconc}. If you do this, your program will change | 1174 | argument to @code{nconc}. If you do this, the resulting behavior |
| 1170 | each time you run it! Here is what happens: | 1175 | is undefined. It is possible that your program will change |
| 1176 | each time you run it! Here is what might happen (though this | ||
| 1177 | is not guaranteed to happen): | ||
| 1171 | 1178 | ||
| 1172 | @smallexample | 1179 | @smallexample |
| 1173 | @group | 1180 | @group |
| @@ -1270,7 +1277,7 @@ removing it involves changing the @sc{cdr}s (@pxref{Setcdr}). | |||
| 1270 | 1277 | ||
| 1271 | @example | 1278 | @example |
| 1272 | @group | 1279 | @group |
| 1273 | (setq sample-list '(a b c (4))) | 1280 | (setq sample-list (list 'a 'b 'c '(4))) |
| 1274 | @result{} (a b c (4)) | 1281 | @result{} (a b c (4)) |
| 1275 | @end group | 1282 | @end group |
| 1276 | @group | 1283 | @group |
| @@ -1303,12 +1310,12 @@ into the variable that held the original list: | |||
| 1303 | (setq flowers (delq 'rose flowers)) | 1310 | (setq flowers (delq 'rose flowers)) |
| 1304 | @end example | 1311 | @end example |
| 1305 | 1312 | ||
| 1306 | In the following example, the @code{(4)} that @code{delq} attempts to match | 1313 | In the following example, the @code{(list 4)} that @code{delq} attempts to match |
| 1307 | and the @code{(4)} in the @code{sample-list} are not @code{eq}: | 1314 | and the @code{(4)} in the @code{sample-list} are @code{equal} but not @code{eq}: |
| 1308 | 1315 | ||
| 1309 | @example | 1316 | @example |
| 1310 | @group | 1317 | @group |
| 1311 | (delq '(4) sample-list) | 1318 | (delq (list 4) sample-list) |
| 1312 | @result{} (a c (4)) | 1319 | @result{} (a c (4)) |
| 1313 | @end group | 1320 | @end group |
| 1314 | @end example | 1321 | @end example |
| @@ -1324,7 +1331,7 @@ of @code{list}. | |||
| 1324 | 1331 | ||
| 1325 | @example | 1332 | @example |
| 1326 | @group | 1333 | @group |
| 1327 | (setq sample-list '(a b c a b c)) | 1334 | (setq sample-list (list 'a 'b 'c 'a 'b 'c)) |
| 1328 | @result{} (a b c a b c) | 1335 | @result{} (a b c a b c) |
| 1329 | @end group | 1336 | @end group |
| 1330 | @group | 1337 | @group |
| @@ -1349,12 +1356,12 @@ Compare this with @code{memq}: | |||
| 1349 | 1356 | ||
| 1350 | @example | 1357 | @example |
| 1351 | @group | 1358 | @group |
| 1352 | (memql 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} are @code{eql}.} | 1359 | (memql 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} must be @code{eql}.} |
| 1353 | @result{} (1.2 1.3) | 1360 | @result{} (1.2 1.3) |
| 1354 | @end group | 1361 | @end group |
| 1355 | @group | 1362 | @group |
| 1356 | (memq 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} are not @code{eq}.} | 1363 | (memq 1.2 '(1.1 1.2 1.3)) ; @r{@code{1.2} and @code{1.2} need not be @code{eq}.} |
| 1357 | @result{} nil | 1364 | @result{} nil ; @r{... or it might be @code{(1.2 1.3)}.} |
| 1358 | @end group | 1365 | @end group |
| 1359 | @end example | 1366 | @end example |
| 1360 | @end defun | 1367 | @end defun |
| @@ -1373,11 +1380,11 @@ Compare this with @code{memq}: | |||
| 1373 | 1380 | ||
| 1374 | @example | 1381 | @example |
| 1375 | @group | 1382 | @group |
| 1376 | (member '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are @code{equal}.} | 1383 | (member (list 2) '((1) (2))) ; @r{@code{(list 2)} and @code{(2)} are @code{equal}.} |
| 1377 | @result{} ((2)) | 1384 | @result{} ((2)) |
| 1378 | @end group | 1385 | @end group |
| 1379 | @group | 1386 | @group |
| 1380 | (memq '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are not @code{eq}.} | 1387 | (memq (list 2) '((1) (2))) ; @r{@code{(list 2)} and @code{(2)} are not @code{eq}.} |
| 1381 | @result{} nil | 1388 | @result{} nil |
| 1382 | @end group | 1389 | @end group |
| 1383 | @group | 1390 | @group |
| @@ -1407,7 +1414,7 @@ For example: | |||
| 1407 | 1414 | ||
| 1408 | @example | 1415 | @example |
| 1409 | @group | 1416 | @group |
| 1410 | (setq l '((2) (1) (2))) | 1417 | (setq l (list '(2) '(1) '(2))) |
| 1411 | (delete '(2) l) | 1418 | (delete '(2) l) |
| 1412 | @result{} ((1)) | 1419 | @result{} ((1)) |
| 1413 | l | 1420 | l |
| @@ -1416,7 +1423,7 @@ l | |||
| 1416 | ;; @r{write @code{(setq l (delete '(2) l))}.} | 1423 | ;; @r{write @code{(setq l (delete '(2) l))}.} |
| 1417 | @end group | 1424 | @end group |
| 1418 | @group | 1425 | @group |
| 1419 | (setq l '((2) (1) (2))) | 1426 | (setq l (list '(2) '(1) '(2))) |
| 1420 | (delete '(1) l) | 1427 | (delete '(1) l) |
| 1421 | @result{} ((2) (2)) | 1428 | @result{} ((2) (2)) |
| 1422 | l | 1429 | l |
| @@ -1618,9 +1625,10 @@ keys may not be symbols: | |||
| 1618 | '(("simple leaves" . oak) | 1625 | '(("simple leaves" . oak) |
| 1619 | ("compound leaves" . horsechestnut))) | 1626 | ("compound leaves" . horsechestnut))) |
| 1620 | 1627 | ||
| 1621 | (assq "simple leaves" leaves) | 1628 | ;; @r{The @code{copy-sequence} means the keys are not @code{eq}.} |
| 1629 | (assq (copy-sequence "simple leaves") leaves) | ||
| 1622 | @result{} nil | 1630 | @result{} nil |
| 1623 | (assoc "simple leaves" leaves) | 1631 | (assoc (copy-sequence "simple leaves") leaves) |
| 1624 | @result{} ("simple leaves" . oak) | 1632 | @result{} ("simple leaves" . oak) |
| 1625 | @end smallexample | 1633 | @end smallexample |
| 1626 | @end defun | 1634 | @end defun |
| @@ -1759,7 +1767,7 @@ correct results, use the return value of @code{assq-delete-all} rather | |||
| 1759 | than looking at the saved value of @var{alist}. | 1767 | than looking at the saved value of @var{alist}. |
| 1760 | 1768 | ||
| 1761 | @example | 1769 | @example |
| 1762 | (setq alist '((foo 1) (bar 2) (foo 3) (lose 4))) | 1770 | (setq alist (list '(foo 1) '(bar 2) '(foo 3) '(lose 4))) |
| 1763 | @result{} ((foo 1) (bar 2) (foo 3) (lose 4)) | 1771 | @result{} ((foo 1) (bar 2) (foo 3) (lose 4)) |
| 1764 | (assq-delete-all 'foo alist) | 1772 | (assq-delete-all 'foo alist) |
| 1765 | @result{} ((bar 2) (lose 4)) | 1773 | @result{} ((bar 2) (lose 4)) |
| @@ -1926,7 +1934,7 @@ function returns the modified property list, so you can store that back | |||
| 1926 | in the place where you got @var{plist}. For example, | 1934 | in the place where you got @var{plist}. For example, |
| 1927 | 1935 | ||
| 1928 | @example | 1936 | @example |
| 1929 | (setq my-plist '(bar t foo 4)) | 1937 | (setq my-plist (list 'bar t 'foo 4)) |
| 1930 | @result{} (bar t foo 4) | 1938 | @result{} (bar t foo 4) |
| 1931 | (setq my-plist (plist-put my-plist 'foo 69)) | 1939 | (setq my-plist (plist-put my-plist 'foo 69)) |
| 1932 | @result{} (bar t foo 69) | 1940 | @result{} (bar t foo 69) |
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 | |||
| 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. | ||
| 50 | Others are @dfn{mutable}: their values can be changed via destructive | ||
| 51 | operations 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 |
| 50 | syntax of each of the standard types in GNU Emacs Lisp. Details on how | 54 | syntax of each of the standard types in GNU Emacs Lisp. Details on how |
| 51 | to use these types can be found in later chapters. | 55 | to 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. | ||
| 2392 | For example, you can create a new integer by calculating one, but you | ||
| 2393 | cannot modify the value of an existing integer. | ||
| 2394 | |||
| 2395 | Other Lisp objects are mutable: their values can be changed | ||
| 2396 | via destructive operations involving side effects. For example, an | ||
| 2397 | existing marker can be changed by moving the marker to point to | ||
| 2398 | somewhere else. | ||
| 2399 | |||
| 2400 | Although numbers are always constants and markers are always | ||
| 2401 | mutable, some types contain both constant and mutable members. These | ||
| 2402 | types include conses, vectors, strings, and symbols. For example, the string | ||
| 2403 | literal @code{"aaa"} yields a constant string, whereas the function | ||
| 2404 | call @code{(make-string 3 ?a)} yields a mutable string that can be | ||
| 2405 | changed via later calls to @code{aset}. | ||
| 2406 | |||
| 2407 | Trying to modify a constant variable signals an error | ||
| 2408 | (@pxref{Constant Variables}). | ||
| 2409 | A program should not attempt to modify other types of constants because the | ||
| 2410 | resulting behavior is undefined: the Lisp interpreter might or might | ||
| 2411 | not detect the error, and if it does not detect the error the | ||
| 2412 | interpreter can behave unpredictably thereafter. Another way to put | ||
| 2413 | this is that although mutable objects are safe to change and constant | ||
| 2414 | symbols reliably reject attempts to change them, other constants are | ||
| 2415 | not safely mutable: if you try to change one your program might | ||
| 2416 | behave as you expect but it might crash or worse. This problem occurs | ||
| 2417 | with types that have both constant and mutable members, and that have | ||
| 2418 | mutators like @code{setcar} and @code{aset} that are valid on mutable | ||
| 2419 | objects but hazardous on constants. | ||
| 2420 | |||
| 2421 | When the same constant occurs multiple times in a program, the Lisp | ||
| 2422 | interpreter might save time or space by reusing existing constants or | ||
| 2423 | constant components. For example, @code{(eq "abc" "abc")} returns | ||
| 2424 | @code{t} if the interpreter creates only one instance of the string | ||
| 2425 | constant @code{"abc"}, and returns @code{nil} if it creates two | ||
| 2426 | instances. Lisp programs should be written so that they work | ||
| 2427 | regardless of whether this optimization is in use. | ||
diff --git a/doc/lispref/os.texi b/doc/lispref/os.texi index e72858bbf1a..5c0b1e2edf0 100644 --- a/doc/lispref/os.texi +++ b/doc/lispref/os.texi | |||
| @@ -2617,7 +2617,7 @@ if it is non-@code{nil}; this can be overridden by binding | |||
| 2617 | This variable is non-@code{nil} when Emacs is running in batch mode. | 2617 | This variable is non-@code{nil} when Emacs is running in batch mode. |
| 2618 | @end defvar | 2618 | @end defvar |
| 2619 | 2619 | ||
| 2620 | If Emacs exits due to signalling an error in batch mode, the exit | 2620 | If Emacs exits due to signaling an error in batch mode, the exit |
| 2621 | status of the Emacs command is non-zero: | 2621 | status of the Emacs command is non-zero: |
| 2622 | 2622 | ||
| 2623 | @example | 2623 | @example |
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi index 1a3a04f680b..1cb0d05cc7b 100644 --- a/doc/lispref/sequences.texi +++ b/doc/lispref/sequences.texi | |||
| @@ -183,11 +183,11 @@ for other ways to copy sequences. | |||
| 183 | 183 | ||
| 184 | @example | 184 | @example |
| 185 | @group | 185 | @group |
| 186 | (setq bar '(1 2)) | 186 | (setq bar (list 1 2)) ; @r{Create a mutable list.} |
| 187 | @result{} (1 2) | 187 | @result{} (1 2) |
| 188 | @end group | 188 | @end group |
| 189 | @group | 189 | @group |
| 190 | (setq x (vector 'foo bar)) | 190 | (setq x (vector 'foo bar)) ; @r{Create a mutable vector.} |
| 191 | @result{} [foo (1 2)] | 191 | @result{} [foo (1 2)] |
| 192 | @end group | 192 | @end group |
| 193 | @group | 193 | @group |
| @@ -278,7 +278,7 @@ Unlike @code{reverse} the original @var{sequence} may be modified. | |||
| 278 | 278 | ||
| 279 | @example | 279 | @example |
| 280 | @group | 280 | @group |
| 281 | (setq x '(a b c)) | 281 | (setq x (list 'a 'b 'c)) ; @r{Create a mutable list.} |
| 282 | @result{} (a b c) | 282 | @result{} (a b c) |
| 283 | @end group | 283 | @end group |
| 284 | @group | 284 | @group |
| @@ -320,7 +320,7 @@ presented graphically: | |||
| 320 | For the vector, it is even simpler because you don't need setq: | 320 | For the vector, it is even simpler because you don't need setq: |
| 321 | 321 | ||
| 322 | @example | 322 | @example |
| 323 | (setq x [1 2 3 4]) | 323 | (setq x (copy-sequence [1 2 3 4])) ; @r{Create a mutable vector.} |
| 324 | @result{} [1 2 3 4] | 324 | @result{} [1 2 3 4] |
| 325 | (nreverse x) | 325 | (nreverse x) |
| 326 | @result{} [4 3 2 1] | 326 | @result{} [4 3 2 1] |
| @@ -330,7 +330,7 @@ x | |||
| 330 | 330 | ||
| 331 | Note that unlike @code{reverse}, this function doesn't work with strings. | 331 | Note that unlike @code{reverse}, this function doesn't work with strings. |
| 332 | Although you can alter string data by using @code{aset}, it is strongly | 332 | Although you can alter string data by using @code{aset}, it is strongly |
| 333 | encouraged to treat strings as immutable. | 333 | encouraged to treat strings as immutable even when they are mutable. |
| 334 | 334 | ||
| 335 | @end defun | 335 | @end defun |
| 336 | 336 | ||
| @@ -374,11 +374,11 @@ appears in a different position in the list due to the change of | |||
| 374 | 374 | ||
| 375 | @example | 375 | @example |
| 376 | @group | 376 | @group |
| 377 | (setq nums '(1 3 2 6 5 4 0)) | 377 | (setq nums (list 1 3 2 6 5 4 0)) ; @r{Create a mutable list.} |
| 378 | @result{} (1 3 2 6 5 4 0) | 378 | @result{} (1 3 2 6 5 4 0) |
| 379 | @end group | 379 | @end group |
| 380 | @group | 380 | @group |
| 381 | (sort nums '<) | 381 | (sort nums #'<) |
| 382 | @result{} (0 1 2 3 4 5 6) | 382 | @result{} (0 1 2 3 4 5 6) |
| 383 | @end group | 383 | @end group |
| 384 | @group | 384 | @group |
| @@ -396,7 +396,7 @@ of @code{sort} and use that. Most often we store the result back into | |||
| 396 | the variable that held the original list: | 396 | the variable that held the original list: |
| 397 | 397 | ||
| 398 | @example | 398 | @example |
| 399 | (setq nums (sort nums '<)) | 399 | (setq nums (sort nums #'<)) |
| 400 | @end example | 400 | @end example |
| 401 | 401 | ||
| 402 | For the better understanding of what stable sort is, consider the following | 402 | For the better understanding of what stable sort is, consider the following |
| @@ -1228,7 +1228,7 @@ This function sets the @var{index}th element of @var{array} to be | |||
| 1228 | 1228 | ||
| 1229 | @example | 1229 | @example |
| 1230 | @group | 1230 | @group |
| 1231 | (setq w [foo bar baz]) | 1231 | (setq w (vector 'foo 'bar 'baz)) ; @r{Create a mutable vector.} |
| 1232 | @result{} [foo bar baz] | 1232 | @result{} [foo bar baz] |
| 1233 | (aset w 0 'fu) | 1233 | (aset w 0 'fu) |
| 1234 | @result{} fu | 1234 | @result{} fu |
| @@ -1237,7 +1237,8 @@ w | |||
| 1237 | @end group | 1237 | @end group |
| 1238 | 1238 | ||
| 1239 | @group | 1239 | @group |
| 1240 | (setq x "asdfasfd") | 1240 | ;; @r{@code{copy-sequence} creates a mutable string.} |
| 1241 | (setq x (copy-sequence "asdfasfd")) | ||
| 1241 | @result{} "asdfasfd" | 1242 | @result{} "asdfasfd" |
| 1242 | (aset x 3 ?Z) | 1243 | (aset x 3 ?Z) |
| 1243 | @result{} 90 | 1244 | @result{} 90 |
| @@ -1246,6 +1247,10 @@ x | |||
| 1246 | @end group | 1247 | @end group |
| 1247 | @end example | 1248 | @end example |
| 1248 | 1249 | ||
| 1250 | The @var{array} should be mutable; that is, it should not be a constant, | ||
| 1251 | such as the constants created via quoting or via self-evaluating forms. | ||
| 1252 | @xref{Constants and Mutability}. | ||
| 1253 | |||
| 1249 | If @var{array} is a string and @var{object} is not a character, a | 1254 | If @var{array} is a string and @var{object} is not a character, a |
| 1250 | @code{wrong-type-argument} error results. The function converts a | 1255 | @code{wrong-type-argument} error results. The function converts a |
| 1251 | unibyte string to multibyte if necessary to insert a character. | 1256 | unibyte string to multibyte if necessary to insert a character. |
| @@ -1257,7 +1262,8 @@ each element of @var{array} is @var{object}. It returns @var{array}. | |||
| 1257 | 1262 | ||
| 1258 | @example | 1263 | @example |
| 1259 | @group | 1264 | @group |
| 1260 | (setq a [a b c d e f g]) | 1265 | ;; @r{Create a mutable vector and then fill it with zeros.} |
| 1266 | (setq a (copy-sequence [a b c d e f g])) | ||
| 1261 | @result{} [a b c d e f g] | 1267 | @result{} [a b c d e f g] |
| 1262 | (fillarray a 0) | 1268 | (fillarray a 0) |
| 1263 | @result{} [0 0 0 0 0 0 0] | 1269 | @result{} [0 0 0 0 0 0 0] |
| @@ -1265,7 +1271,8 @@ a | |||
| 1265 | @result{} [0 0 0 0 0 0 0] | 1271 | @result{} [0 0 0 0 0 0 0] |
| 1266 | @end group | 1272 | @end group |
| 1267 | @group | 1273 | @group |
| 1268 | (setq s "When in the course") | 1274 | ;; @r{Create a mutable string and then fill it with "-".} |
| 1275 | (setq s (copy-sequence "When in the course")) | ||
| 1269 | @result{} "When in the course" | 1276 | @result{} "When in the course" |
| 1270 | (fillarray s ?-) | 1277 | (fillarray s ?-) |
| 1271 | @result{} "------------------" | 1278 | @result{} "------------------" |
| @@ -1302,7 +1309,9 @@ same way in Lisp input. | |||
| 1302 | A vector, like a string or a number, is considered a constant for | 1309 | A vector, like a string or a number, is considered a constant for |
| 1303 | evaluation: the result of evaluating it is the same vector. This does | 1310 | evaluation: the result of evaluating it is the same vector. This does |
| 1304 | not evaluate or even examine the elements of the vector. | 1311 | not evaluate or even examine the elements of the vector. |
| 1305 | @xref{Self-Evaluating Forms}. | 1312 | @xref{Self-Evaluating Forms}. Vectors written with square brackets |
| 1313 | are constants and should not be modified via @code{aset} or other | ||
| 1314 | destructive operations. @xref{Constants and Mutability}. | ||
| 1306 | 1315 | ||
| 1307 | Here are examples illustrating these principles: | 1316 | Here are examples illustrating these principles: |
| 1308 | 1317 | ||
| @@ -1565,14 +1574,14 @@ For example, here is how to examine the elements of the syntax table: | |||
| 1565 | @example | 1574 | @example |
| 1566 | (let (accumulator) | 1575 | (let (accumulator) |
| 1567 | (map-char-table | 1576 | (map-char-table |
| 1568 | #'(lambda (key value) | 1577 | (lambda (key value) |
| 1569 | (setq accumulator | 1578 | (setq accumulator |
| 1570 | (cons (list | 1579 | (cons (list |
| 1571 | (if (consp key) | 1580 | (if (consp key) |
| 1572 | (list (car key) (cdr key)) | 1581 | (list (car key) (cdr key)) |
| 1573 | key) | 1582 | key) |
| 1574 | value) | 1583 | value) |
| 1575 | accumulator))) | 1584 | accumulator))) |
| 1576 | (syntax-table)) | 1585 | (syntax-table)) |
| 1577 | accumulator) | 1586 | accumulator) |
| 1578 | @result{} | 1587 | @result{} |
diff --git a/doc/lispref/strings.texi b/doc/lispref/strings.texi index 14cabc5d79d..a4c9c2549c5 100644 --- a/doc/lispref/strings.texi +++ b/doc/lispref/strings.texi | |||
| @@ -51,10 +51,8 @@ by a distinguished character code. | |||
| 51 | operate on them with the general array and sequence functions documented | 51 | operate on them with the general array and sequence functions documented |
| 52 | in @ref{Sequences Arrays Vectors}. For example, you can access or | 52 | in @ref{Sequences Arrays Vectors}. For example, you can access or |
| 53 | change individual characters in a string using the functions @code{aref} | 53 | change individual characters in a string using the functions @code{aref} |
| 54 | and @code{aset} (@pxref{Array Functions}). However, note that | 54 | and @code{aset} (@pxref{Array Functions}). However, you should not |
| 55 | @code{length} should @emph{not} be used for computing the width of a | 55 | try to change the contents of constant strings (@pxref{Modifying Strings}). |
| 56 | string on display; use @code{string-width} (@pxref{Size of Displayed | ||
| 57 | Text}) instead. | ||
| 58 | 56 | ||
| 59 | There are two text representations for non-@acronym{ASCII} | 57 | There are two text representations for non-@acronym{ASCII} |
| 60 | characters in Emacs strings (and in buffers): unibyte and multibyte. | 58 | characters in Emacs strings (and in buffers): unibyte and multibyte. |
| @@ -89,6 +87,9 @@ copy them into buffers. @xref{Character Type}, and @ref{String Type}, | |||
| 89 | for information about the syntax of characters and strings. | 87 | for information about the syntax of characters and strings. |
| 90 | @xref{Non-ASCII Characters}, for functions to convert between text | 88 | @xref{Non-ASCII Characters}, for functions to convert between text |
| 91 | representations and to encode and decode character codes. | 89 | representations and to encode and decode character codes. |
| 90 | Also, note that @code{length} should @emph{not} be used for computing | ||
| 91 | the width of a string on display; use @code{string-width} (@pxref{Size | ||
| 92 | of Displayed Text}) instead. | ||
| 92 | 93 | ||
| 93 | @node Predicates for Strings | 94 | @node Predicates for Strings |
| 94 | @section Predicates for Strings | 95 | @section Predicates for Strings |
| @@ -380,6 +381,11 @@ usual value is @w{@code{"[ \f\t\n\r\v]+"}}. | |||
| 380 | @cindex modifying strings | 381 | @cindex modifying strings |
| 381 | @cindex string modification | 382 | @cindex string modification |
| 382 | 383 | ||
| 384 | You can alter the contents of a mutable string via operations | ||
| 385 | described in this section. However, you should not try to use these | ||
| 386 | operations to alter the contents of a constant string. | ||
| 387 | @xref{Constants and Mutability}. | ||
| 388 | |||
| 383 | The most basic way to alter the contents of an existing string is with | 389 | The most basic way to alter the contents of an existing string is with |
| 384 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} | 390 | @code{aset} (@pxref{Array Functions}). @code{(aset @var{string} |
| 385 | @var{idx} @var{char})} stores @var{char} into @var{string} at index | 391 | @var{idx} @var{char})} stores @var{char} into @var{string} at index |
| @@ -591,7 +597,7 @@ for sorting (@pxref{Sequence Functions}): | |||
| 591 | 597 | ||
| 592 | @example | 598 | @example |
| 593 | @group | 599 | @group |
| 594 | (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) | 600 | (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2") 'string-collate-lessp) |
| 595 | @result{} ("11" "1 1" "1.1" "12" "1 2" "1.2") | 601 | @result{} ("11" "1 1" "1.1" "12" "1 2" "1.2") |
| 596 | @end group | 602 | @end group |
| 597 | @end example | 603 | @end example |
| @@ -608,7 +614,7 @@ systems. The @var{locale} value of @code{"POSIX"} or @code{"C"} lets | |||
| 608 | 614 | ||
| 609 | @example | 615 | @example |
| 610 | @group | 616 | @group |
| 611 | (sort '("11" "12" "1 1" "1 2" "1.1" "1.2") | 617 | (sort (list "11" "12" "1 1" "1 2" "1.1" "1.2") |
| 612 | (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX"))) | 618 | (lambda (s1 s2) (string-collate-lessp s1 s2 "POSIX"))) |
| 613 | @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12") | 619 | @result{} ("1 1" "1 2" "1.1" "1.2" "11" "12") |
| 614 | @end group | 620 | @end group |
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi index ad45a8edaff..9eb99a0ac92 100644 --- a/doc/lispref/syntax.texi +++ b/doc/lispref/syntax.texi | |||
| @@ -1118,9 +1118,9 @@ bidi-class}). | |||
| 1118 | ;; 'bidi-class' Unicode property is R, AL, or RLO -- | 1118 | ;; 'bidi-class' Unicode property is R, AL, or RLO -- |
| 1119 | ;; these have a right-to-left directionality. | 1119 | ;; these have a right-to-left directionality. |
| 1120 | (map-char-table | 1120 | (map-char-table |
| 1121 | #'(lambda (key val) | 1121 | (lambda (key val) |
| 1122 | (if (memq val '(R AL RLO)) | 1122 | (if (memq val '(R AL RLO)) |
| 1123 | (modify-category-entry key ?R category-table))) | 1123 | (modify-category-entry key ?R category-table))) |
| 1124 | uniprop-table) | 1124 | uniprop-table) |
| 1125 | category-table)) | 1125 | category-table)) |
| 1126 | @end example | 1126 | @end example |
diff --git a/doc/lispref/text.texi b/doc/lispref/text.texi index ffdf952b081..58424a4231b 100644 --- a/doc/lispref/text.texi +++ b/doc/lispref/text.texi | |||
| @@ -2073,11 +2073,10 @@ its @code{sort-subr} call looks like this: | |||
| 2073 | @example | 2073 | @example |
| 2074 | @group | 2074 | @group |
| 2075 | (sort-subr reverse | 2075 | (sort-subr reverse |
| 2076 | (function | 2076 | (lambda () |
| 2077 | (lambda () | 2077 | (while (and (not (eobp)) |
| 2078 | (while (and (not (eobp)) | 2078 | (looking-at paragraph-separate)) |
| 2079 | (looking-at paragraph-separate)) | 2079 | (forward-line 1))) |
| 2080 | (forward-line 1)))) | ||
| 2081 | 'forward-paragraph) | 2080 | 'forward-paragraph) |
| 2082 | @end group | 2081 | @end group |
| 2083 | @end example | 2082 | @end example |
| @@ -4679,7 +4678,7 @@ expanded when the header line is computed. To do this, the | |||
| 4679 | above. @var{specification} is an alist that has elements where the | 4678 | above. @var{specification} is an alist that has elements where the |
| 4680 | @code{car} is a character and the @code{cdr} is the substitution. | 4679 | @code{car} is a character and the @code{cdr} is the substitution. |
| 4681 | 4680 | ||
| 4682 | If @code{ONLY-PRESENT} is @code{nil}, errors will be signalled if a | 4681 | If @code{ONLY-PRESENT} is @code{nil}, errors will be signaled if a |
| 4683 | format character has been used that's not present in | 4682 | format character has been used that's not present in |
| 4684 | @var{specification}. If it's non-@code{nil}, that format | 4683 | @var{specification}. If it's non-@code{nil}, that format |
| 4685 | specification is left verbatim in the result. | 4684 | specification is left verbatim in the result. |
| @@ -5725,7 +5724,7 @@ made within the @code{combine-after-change-calls} body. | |||
| 5725 | @code{after-change-functions} within | 5724 | @code{after-change-functions} within |
| 5726 | the body of a @code{combine-after-change-calls} form. | 5725 | the body of a @code{combine-after-change-calls} form. |
| 5727 | 5726 | ||
| 5728 | @strong{Warning:} if the changes you combine occur in widely scattered | 5727 | @strong{Warning:} If the changes you combine occur in widely scattered |
| 5729 | parts of the buffer, this will still work, but it is not advisable, | 5728 | parts of the buffer, this will still work, but it is not advisable, |
| 5730 | because it may lead to inefficient behavior for some change hook | 5729 | because it may lead to inefficient behavior for some change hook |
| 5731 | functions. | 5730 | functions. |