diff options
| author | Richard M. Stallman | 1994-04-26 22:08:09 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-26 22:08:09 +0000 |
| commit | 2b3fc6c3053c124f9f128152d9456bfe90151cc6 (patch) | |
| tree | 118d88a3734cecba17e9bf04d75373c6356f76ac | |
| parent | a1a7207a13168b6231e46ee44b39c661fd0c6128 (diff) | |
| download | emacs-2b3fc6c3053c124f9f128152d9456bfe90151cc6.tar.gz emacs-2b3fc6c3053c124f9f128152d9456bfe90151cc6.zip | |
*** empty log message ***
| -rw-r--r-- | lispref/lists.texi | 160 | ||||
| -rw-r--r-- | lispref/objects.texi | 254 | ||||
| -rw-r--r-- | lispref/symbols.texi | 36 |
3 files changed, 252 insertions, 198 deletions
diff --git a/lispref/lists.texi b/lispref/lists.texi index 8253063d2ce..1ec45ab20ca 100644 --- a/lispref/lists.texi +++ b/lispref/lists.texi | |||
| @@ -31,10 +31,10 @@ the whole list. | |||
| 31 | @cindex @code{nil} and lists | 31 | @cindex @code{nil} and lists |
| 32 | 32 | ||
| 33 | Lists in Lisp are not a primitive data type; they are built up from | 33 | Lists in Lisp are not a primitive data type; they are built up from |
| 34 | @dfn{cons cells}. A cons cell is a data object which represents an ordered | 34 | @dfn{cons cells}. A cons cell is a data object that represents an |
| 35 | pair. It records two Lisp objects, one labeled as the @sc{car}, and the | 35 | ordered pair. It records two Lisp objects, one labeled as the @sc{car}, |
| 36 | other labeled as the @sc{cdr}. These names are traditional; @sc{cdr} is | 36 | and the other labeled as the @sc{cdr}. These names are traditional; see |
| 37 | pronounced ``could-er.'' | 37 | @ref{Cons Cell Type}. @sc{cdr} is pronounced ``could-er.'' |
| 38 | 38 | ||
| 39 | A list is a series of cons cells chained together, one cons cell per | 39 | A list is a series of cons cells chained together, one cons cell per |
| 40 | element of the list. By convention, the @sc{car}s of the cons cells are | 40 | element of the list. By convention, the @sc{car}s of the cons cells are |
| @@ -45,6 +45,11 @@ of the last cons cell is @code{nil}. This asymmetry between the | |||
| 45 | level of cons cells, the @sc{car} and @sc{cdr} slots have the same | 45 | level of cons cells, the @sc{car} and @sc{cdr} slots have the same |
| 46 | characteristics. | 46 | characteristics. |
| 47 | 47 | ||
| 48 | @cindex list structure | ||
| 49 | Because most cons cells are used as part of lists, the phrase | ||
| 50 | @dfn{list structure} has come to mean any structure made out of cons | ||
| 51 | cells. | ||
| 52 | |||
| 48 | The symbol @code{nil} is considered a list as well as a symbol; it is | 53 | The symbol @code{nil} is considered a list as well as a symbol; it is |
| 49 | the list with no elements. For convenience, the symbol @code{nil} is | 54 | the list with no elements. For convenience, the symbol @code{nil} is |
| 50 | considered to have @code{nil} as its @sc{cdr} (and also as its | 55 | considered to have @code{nil} as its @sc{cdr} (and also as its |
| @@ -134,8 +139,8 @@ two-element list: | |||
| 134 | @end group | 139 | @end group |
| 135 | @end example | 140 | @end example |
| 136 | 141 | ||
| 137 | @xref{List Type}, for the read and print syntax of lists, and for more | 142 | @xref{Cons Cell Type}, for the read and print syntax of cons cells and |
| 138 | ``box and arrow'' illustrations of lists. | 143 | lists, and for more ``box and arrow'' illustrations of lists. |
| 139 | 144 | ||
| 140 | @node List-related Predicates | 145 | @node List-related Predicates |
| 141 | @section Predicates on Lists | 146 | @section Predicates on Lists |
| @@ -155,7 +160,7 @@ otherwise. @code{nil} is not a cons cell, although it @emph{is} a list. | |||
| 155 | This function returns @code{t} if @var{object} is an atom, @code{nil} | 160 | This function returns @code{t} if @var{object} is an atom, @code{nil} |
| 156 | otherwise. All objects except cons cells are atoms. The symbol | 161 | otherwise. All objects except cons cells are atoms. The symbol |
| 157 | @code{nil} is an atom and is also a list; it is the only Lisp object | 162 | @code{nil} is an atom and is also a list; it is the only Lisp object |
| 158 | which is both. | 163 | that is both. |
| 159 | 164 | ||
| 160 | @example | 165 | @example |
| 161 | (atom @var{object}) @equiv{} (not (consp @var{object})) | 166 | (atom @var{object}) @equiv{} (not (consp @var{object})) |
| @@ -433,15 +438,22 @@ elements have the identical value @var{object}. Compare | |||
| 433 | @defun append &rest sequences | 438 | @defun append &rest sequences |
| 434 | @cindex copying lists | 439 | @cindex copying lists |
| 435 | This function returns a list containing all the elements of | 440 | This function returns a list containing all the elements of |
| 436 | @var{sequences}. The @var{sequences} may be lists, vectors, or strings. | 441 | @var{sequences}. The @var{sequences} may be lists, vectors, or strings, |
| 437 | All arguments except the last one are copied, so none of them are | 442 | but the last one should be a list. All arguments except the last one |
| 438 | altered. | 443 | are copied, so none of them are altered. |
| 444 | |||
| 445 | More generally, the final argument to @code{append} may be any Lisp | ||
| 446 | object. The final argument is not copied or converted; it becomes the | ||
| 447 | @sc{cdr} of the last cons cell in the new list. If the final argument | ||
| 448 | is itself a list, then its elements become in effect elements of the | ||
| 449 | result list. If the final element is not a list, the result is a | ||
| 450 | ``dotted list'' since its final @sc{cdr} is not @code{nil} as required | ||
| 451 | in a true list. | ||
| 439 | 452 | ||
| 440 | The final argument to @code{append} may be any object but it is | 453 | See @code{nconc} in @ref{Rearrangement}, for a way to join lists with no |
| 441 | typically a list. The final argument is not copied or converted; it | 454 | copying. |
| 442 | becomes part of the structure of the new list. | ||
| 443 | 455 | ||
| 444 | Here is an example: | 456 | Here is an example of using @code{append}: |
| 445 | 457 | ||
| 446 | @example | 458 | @example |
| 447 | @group | 459 | @group |
| @@ -463,11 +475,11 @@ more-trees | |||
| 463 | @end group | 475 | @end group |
| 464 | @end example | 476 | @end example |
| 465 | 477 | ||
| 466 | You can see what happens by looking at a box diagram. The variable | 478 | You can see how @code{append} works by looking at a box diagram. The |
| 467 | @code{trees} is set to the list @code{(pine oak)} and then the variable | 479 | variable @code{trees} is set to the list @code{(pine oak)} and then the |
| 468 | @code{more-trees} is set to the list @code{(maple birch pine oak)}. | 480 | variable @code{more-trees} is set to the list @code{(maple birch pine |
| 469 | However, the variable @code{trees} continues to refer to the original | 481 | oak)}. However, the variable @code{trees} continues to refer to the |
| 470 | list: | 482 | original list: |
| 471 | 483 | ||
| 472 | @smallexample | 484 | @smallexample |
| 473 | @group | 485 | @group |
| @@ -527,8 +539,20 @@ If no @var{sequences} are given, @code{nil} is returned: | |||
| 527 | @end group | 539 | @end group |
| 528 | @end example | 540 | @end example |
| 529 | 541 | ||
| 530 | See @code{nconc} in @ref{Rearrangement}, for a way to join lists with no | 542 | Here are some examples where the final argument is not a list: |
| 531 | copying. | 543 | |
| 544 | @example | ||
| 545 | (append '(x y) 'z) | ||
| 546 | @result{} (x y z) | ||
| 547 | (append '(x y) [z]) | ||
| 548 | @result{} (x y [z]) | ||
| 549 | @end example | ||
| 550 | |||
| 551 | @noindent | ||
| 552 | The second example shows that when the final argument is a sequence but | ||
| 553 | not a list, the sequence's elements do not become elements of the | ||
| 554 | resulting list. Instead, the sequence becomes the final @sc{cdr}, like | ||
| 555 | any other non-list final argument. | ||
| 532 | 556 | ||
| 533 | Integers are also allowed as arguments to @code{append}. They are | 557 | Integers are also allowed as arguments to @code{append}. They are |
| 534 | converted to strings of digits making up the decimal print | 558 | converted to strings of digits making up the decimal print |
| @@ -606,8 +630,9 @@ new @sc{car} or @sc{cdr}. | |||
| 606 | @node Setcar | 630 | @node Setcar |
| 607 | @subsection Altering List Elements with @code{setcar} | 631 | @subsection Altering List Elements with @code{setcar} |
| 608 | 632 | ||
| 609 | Changing the @sc{car} of a cons cell is done with @code{setcar}, which | 633 | Changing the @sc{car} of a cons cell is done with @code{setcar}. When |
| 610 | replaces one element of a list with a different element. | 634 | used on a list, @code{setcar} replaces one element of a list with a |
| 635 | different element. | ||
| 611 | 636 | ||
| 612 | @defun setcar cons object | 637 | @defun setcar cons object |
| 613 | This function stores @var{object} as the new @sc{car} of @var{cons}, | 638 | This function stores @var{object} as the new @sc{car} of @var{cons}, |
| @@ -710,8 +735,8 @@ x2: | | |||
| 710 | The lowest-level primitive for modifying a @sc{cdr} is @code{setcdr}: | 735 | The lowest-level primitive for modifying a @sc{cdr} is @code{setcdr}: |
| 711 | 736 | ||
| 712 | @defun setcdr cons object | 737 | @defun setcdr cons object |
| 713 | This function stores @var{object} into the @sc{cdr} of @var{cons}. The | 738 | This function stores @var{object} as the new @sc{cdr} of @var{cons}, |
| 714 | value returned is @var{object}, not @var{cons}. | 739 | replacing its previous @sc{cdr}. It returns the value @var{object}. |
| 715 | @end defun | 740 | @end defun |
| 716 | 741 | ||
| 717 | Here is an example of replacing the @sc{cdr} of a list with a | 742 | Here is an example of replacing the @sc{cdr} of a list with a |
| @@ -813,6 +838,15 @@ modifying the @sc{cdr}s of their component cons cells. We call these | |||
| 813 | functions ``destructive'' because they chew up the original lists passed | 838 | functions ``destructive'' because they chew up the original lists passed |
| 814 | to them as arguments, to produce a new list that is the returned value. | 839 | to them as arguments, to produce a new list that is the returned value. |
| 815 | 840 | ||
| 841 | @ifinfo | ||
| 842 | See @code{delq}, in @ref{Sets And Lists}, for another function | ||
| 843 | that modifies cons cells. | ||
| 844 | @end ifinfo | ||
| 845 | @iftex | ||
| 846 | The function @code{delq} in the following section is another example | ||
| 847 | of destructive list manipulation. | ||
| 848 | @end iftex | ||
| 849 | |||
| 816 | @defun nconc &rest lists | 850 | @defun nconc &rest lists |
| 817 | @cindex concatenating lists | 851 | @cindex concatenating lists |
| 818 | @cindex joining lists | 852 | @cindex joining lists |
| @@ -895,10 +929,10 @@ each time you run it! Here is what happens: | |||
| 895 | @defun nreverse list | 929 | @defun nreverse list |
| 896 | @cindex reversing a list | 930 | @cindex reversing a list |
| 897 | This function reverses the order of the elements of @var{list}. | 931 | This function reverses the order of the elements of @var{list}. |
| 898 | Unlike @code{reverse}, @code{nreverse} alters its argument destructively | 932 | Unlike @code{reverse}, @code{nreverse} alters its argument by reversing |
| 899 | by reversing the @sc{cdr}s in the cons cells forming the list. The cons | 933 | the @sc{cdr}s in the cons cells forming the list. The cons cell that |
| 900 | cell which used to be the last one in @var{list} becomes the first cell | 934 | used to be the last one in @var{list} becomes the first cell of the |
| 901 | of the value. | 935 | value. |
| 902 | 936 | ||
| 903 | For example: | 937 | For example: |
| 904 | 938 | ||
| @@ -966,6 +1000,11 @@ sorted order. If you wish to make a sorted copy without destroying the | |||
| 966 | original, copy it first with @code{copy-sequence} and then sort. | 1000 | original, copy it first with @code{copy-sequence} and then sort. |
| 967 | 1001 | ||
| 968 | Sorting does not change the @sc{car}s of the cons cells in @var{list}; | 1002 | Sorting does not change the @sc{car}s of the cons cells in @var{list}; |
| 1003 | each cons cell in the result contains the same element that it contained | ||
| 1004 | before. The result differs from the argument @var{list} because the | ||
| 1005 | cells themselves have been reordered. | ||
| 1006 | |||
| 1007 | Sorting does not change the @sc{car}s of the cons cells in @var{list}; | ||
| 969 | the cons cell that originally contained the element @code{a} in | 1008 | the cons cell that originally contained the element @code{a} in |
| 970 | @var{list} still has @code{a} in its @sc{car} after sorting, but it now | 1009 | @var{list} still has @code{a} in its @sc{car} after sorting, but it now |
| 971 | appears in a different position in the list due to the change of | 1010 | appears in a different position in the list due to the change of |
| @@ -1003,15 +1042,6 @@ See @code{documentation} in @ref{Accessing Documentation}, for a | |||
| 1003 | useful example of @code{sort}. | 1042 | useful example of @code{sort}. |
| 1004 | @end defun | 1043 | @end defun |
| 1005 | 1044 | ||
| 1006 | @ifinfo | ||
| 1007 | See @code{delq}, in @ref{Sets And Lists}, for another function | ||
| 1008 | that modifies cons cells. | ||
| 1009 | @end ifinfo | ||
| 1010 | @iftex | ||
| 1011 | The function @code{delq} in the following section is another example | ||
| 1012 | of destructive list manipulation. | ||
| 1013 | @end iftex | ||
| 1014 | |||
| 1015 | @node Sets And Lists | 1045 | @node Sets And Lists |
| 1016 | @section Using Lists as Sets | 1046 | @section Using Lists as Sets |
| 1017 | @cindex lists as sets | 1047 | @cindex lists as sets |
| @@ -1042,8 +1072,8 @@ compare @var{object} against the elements of the list. For example: | |||
| 1042 | 1072 | ||
| 1043 | @example | 1073 | @example |
| 1044 | @group | 1074 | @group |
| 1045 | (memq 2 '(1 2 3 2 1)) | 1075 | (memq 'b '(a b c b a)) |
| 1046 | @result{} (2 3 2 1) | 1076 | @result{} (b c b a) |
| 1047 | @end group | 1077 | @end group |
| 1048 | @group | 1078 | @group |
| 1049 | (memq '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are not @code{eq}.} | 1079 | (memq '(2) '((1) (2))) ; @r{@code{(2)} and @code{(2)} are not @code{eq}.} |
| @@ -1075,29 +1105,29 @@ removing it involves changing the @sc{cdr}s (@pxref{Setcdr}). | |||
| 1075 | 1105 | ||
| 1076 | @example | 1106 | @example |
| 1077 | @group | 1107 | @group |
| 1078 | (setq sample-list '(1 2 3 (4))) | 1108 | (setq sample-list '(a b c (4))) |
| 1079 | @result{} (1 2 3 (4)) | 1109 | @result{} (a b c (4)) |
| 1080 | @end group | 1110 | @end group |
| 1081 | @group | 1111 | @group |
| 1082 | (delq 1 sample-list) | 1112 | (delq 'a sample-list) |
| 1083 | @result{} (2 3 (4)) | 1113 | @result{} (b c (4)) |
| 1084 | @end group | 1114 | @end group |
| 1085 | @group | 1115 | @group |
| 1086 | sample-list | 1116 | sample-list |
| 1087 | @result{} (1 2 3 (4)) | 1117 | @result{} (a b c (4)) |
| 1088 | @end group | 1118 | @end group |
| 1089 | @group | 1119 | @group |
| 1090 | (delq 2 sample-list) | 1120 | (delq 'c sample-list) |
| 1091 | @result{} (1 3 (4)) | 1121 | @result{} (a c (4)) |
| 1092 | @end group | 1122 | @end group |
| 1093 | @group | 1123 | @group |
| 1094 | sample-list | 1124 | sample-list |
| 1095 | @result{} (1 3 (4)) | 1125 | @result{} (a c (4)) |
| 1096 | @end group | 1126 | @end group |
| 1097 | @end example | 1127 | @end example |
| 1098 | 1128 | ||
| 1099 | Note that @code{(delq 2 sample-list)} modifies @code{sample-list} to | 1129 | Note that @code{(delq 'b sample-list)} modifies @code{sample-list} to |
| 1100 | splice out the second element, but @code{(delq 1 sample-list)} does not | 1130 | splice out the second element, but @code{(delq 'a sample-list)} does not |
| 1101 | splice anything---it just returns a shorter list. Don't assume that a | 1131 | splice anything---it just returns a shorter list. Don't assume that a |
| 1102 | variable which formerly held the argument @var{list} now has fewer | 1132 | variable which formerly held the argument @var{list} now has fewer |
| 1103 | elements, or that it still holds the original list! Instead, save the | 1133 | elements, or that it still holds the original list! Instead, save the |
| @@ -1114,7 +1144,7 @@ and the @code{(4)} in the @code{sample-list} are not @code{eq}: | |||
| 1114 | @example | 1144 | @example |
| 1115 | @group | 1145 | @group |
| 1116 | (delq '(4) sample-list) | 1146 | (delq '(4) sample-list) |
| 1117 | @result{} (1 3 (4)) | 1147 | @result{} (a c (4)) |
| 1118 | @end group | 1148 | @end group |
| 1119 | @end example | 1149 | @end example |
| 1120 | 1150 | ||
| @@ -1258,7 +1288,7 @@ For example: | |||
| 1258 | @result{} nil | 1288 | @result{} nil |
| 1259 | @end smallexample | 1289 | @end smallexample |
| 1260 | 1290 | ||
| 1261 | Here is another example in which the keys and values are not symbols: | 1291 | Here is another example, in which the keys and values are not symbols: |
| 1262 | 1292 | ||
| 1263 | @smallexample | 1293 | @smallexample |
| 1264 | (setq needles-per-cluster | 1294 | (setq needles-per-cluster |
| @@ -1353,18 +1383,18 @@ the new alist without changing the old one. | |||
| 1353 | @group | 1383 | @group |
| 1354 | (setq needles-per-cluster | 1384 | (setq needles-per-cluster |
| 1355 | '((2 . ("Austrian Pine" "Red Pine")) | 1385 | '((2 . ("Austrian Pine" "Red Pine")) |
| 1356 | (3 . "Pitch Pine") | 1386 | (3 . ("Pitch Pine")) |
| 1357 | (5 . "White Pine"))) | 1387 | (5 . ("White Pine")))) |
| 1358 | @result{} | 1388 | @result{} |
| 1359 | ((2 "Austrian Pine" "Red Pine") | 1389 | ((2 "Austrian Pine" "Red Pine") |
| 1360 | (3 . "Pitch Pine") | 1390 | (3 "Pitch Pine") |
| 1361 | (5 . "White Pine")) | 1391 | (5 "White Pine")) |
| 1362 | 1392 | ||
| 1363 | (setq copy (copy-alist needles-per-cluster)) | 1393 | (setq copy (copy-alist needles-per-cluster)) |
| 1364 | @result{} | 1394 | @result{} |
| 1365 | ((2 "Austrian Pine" "Red Pine") | 1395 | ((2 "Austrian Pine" "Red Pine") |
| 1366 | (3 . "Pitch Pine") | 1396 | (3 "Pitch Pine") |
| 1367 | (5 . "White Pine")) | 1397 | (5 "White Pine")) |
| 1368 | 1398 | ||
| 1369 | (eq needles-per-cluster copy) | 1399 | (eq needles-per-cluster copy) |
| 1370 | @result{} nil | 1400 | @result{} nil |
| @@ -1373,11 +1403,23 @@ the new alist without changing the old one. | |||
| 1373 | (eq (car needles-per-cluster) (car copy)) | 1403 | (eq (car needles-per-cluster) (car copy)) |
| 1374 | @result{} nil | 1404 | @result{} nil |
| 1375 | (cdr (car (cdr needles-per-cluster))) | 1405 | (cdr (car (cdr needles-per-cluster))) |
| 1376 | @result{} "Pitch Pine" | 1406 | @result{} ("Pitch Pine") |
| 1377 | (eq (cdr (car (cdr needles-per-cluster))) | 1407 | (eq (cdr (car (cdr needles-per-cluster))) |
| 1378 | (cdr (car (cdr copy)))) | 1408 | (cdr (car (cdr copy)))) |
| 1379 | @result{} t | 1409 | @result{} t |
| 1380 | @end group | 1410 | @end group |
| 1411 | @end example | ||
| 1412 | |||
| 1413 | This example shows how @code{copy-alist} makes it possible to change | ||
| 1414 | the associations of one copy without affecting the other: | ||
| 1415 | |||
| 1416 | @example | ||
| 1417 | @group | ||
| 1418 | (setcdr (assq 3 needles-per-cluster) | ||
| 1419 | '("Martian Vacuum Pine")) | ||
| 1420 | (cdr (assq 3 needles-per-cluster)) | ||
| 1421 | @result{} ("Pitch Pine") | ||
| 1422 | @end group | ||
| 1381 | @end smallexample | 1423 | @end smallexample |
| 1382 | @end defun | 1424 | @end defun |
| 1383 | 1425 | ||
diff --git a/lispref/objects.texi b/lispref/objects.texi index ab2fe39a10c..6dd8912671c 100644 --- a/lispref/objects.texi +++ b/lispref/objects.texi | |||
| @@ -3,7 +3,7 @@ | |||
| 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. | 3 | @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc. |
| 4 | @c See the file elisp.texi for copying conditions. | 4 | @c See the file elisp.texi for copying conditions. |
| 5 | @setfilename ../info/objects | 5 | @setfilename ../info/objects |
| 6 | @node Types of Lisp Object, Numbers, Introduction, Top | 6 | @node Lisp Data Types, Numbers, Introduction, Top |
| 7 | @chapter Lisp Data Types | 7 | @chapter Lisp Data Types |
| 8 | @cindex object | 8 | @cindex object |
| 9 | @cindex Lisp object | 9 | @cindex Lisp object |
| @@ -40,8 +40,8 @@ it as a number; Lisp knows it is a vector, not a number. | |||
| 40 | In most languages, the programmer must declare the data type of each | 40 | In most languages, the programmer must declare the data type of each |
| 41 | variable, and the type is known by the compiler but not represented in | 41 | variable, and the type is known by the compiler but not represented in |
| 42 | the data. Such type declarations do not exist in Emacs Lisp. A Lisp | 42 | the data. Such type declarations do not exist in Emacs Lisp. A Lisp |
| 43 | variable can have any type of value, and remembers the type of any value | 43 | variable can have any type of value, and it remembers whatever value |
| 44 | you store in it. | 44 | you store in it, type and all. |
| 45 | 45 | ||
| 46 | This chapter describes the purpose, printed representation, and read | 46 | This chapter describes the purpose, printed representation, and read |
| 47 | syntax of each of the standard types in GNU Emacs Lisp. Details on how | 47 | syntax of each of the standard types in GNU Emacs Lisp. Details on how |
| @@ -132,7 +132,7 @@ latter are unique to Emacs Lisp. | |||
| 132 | * Character Type:: The representation of letters, numbers and | 132 | * Character Type:: The representation of letters, numbers and |
| 133 | control characters. | 133 | control characters. |
| 134 | * Sequence Type:: Both lists and arrays are classified as sequences. | 134 | * Sequence Type:: Both lists and arrays are classified as sequences. |
| 135 | * List Type:: Lists gave Lisp its name (not to mention reputation). | 135 | * Cons Cell Type:: Cons cells, and lists (which are made from cons cells). |
| 136 | * Array Type:: Arrays include strings and vectors. | 136 | * Array Type:: Arrays include strings and vectors. |
| 137 | * String Type:: An (efficient) array of characters. | 137 | * String Type:: An (efficient) array of characters. |
| 138 | * Vector Type:: One-dimensional arrays. | 138 | * Vector Type:: One-dimensional arrays. |
| @@ -170,7 +170,7 @@ to note that the Emacs Lisp arithmetic functions do not check for | |||
| 170 | overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit | 170 | overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit |
| 171 | implementations.@refill | 171 | implementations.@refill |
| 172 | 172 | ||
| 173 | The read syntax for numbers is a sequence of (base ten) digits with an | 173 | The read syntax for integers is a sequence of (base ten) digits with an |
| 174 | optional sign at the beginning and an optional period at the end. The | 174 | optional sign at the beginning and an optional period at the end. The |
| 175 | printed representation produced by the Lisp interpreter never has a | 175 | printed representation produced by the Lisp interpreter never has a |
| 176 | leading @samp{+} or a final @samp{.}. | 176 | leading @samp{+} or a final @samp{.}. |
| @@ -242,10 +242,10 @@ character @kbd{a}. | |||
| 242 | @end example | 242 | @end example |
| 243 | 243 | ||
| 244 | You can use the same syntax for punctuation characters, but it is | 244 | You can use the same syntax for punctuation characters, but it is |
| 245 | often a good idea to add a @samp{\} to prevent Lisp mode from getting | 245 | often a good idea to add a @samp{\} so that the Emacs commands for |
| 246 | confused. For example, @samp{?\ } is the way to write the space | 246 | editing Lisp code don't get confused. For example, @samp{?\ } is the |
| 247 | character. If the character is @samp{\}, you @emph{must} use a second | 247 | way to write the space character. If the character is @samp{\}, you |
| 248 | @samp{\} to quote it: @samp{?\\}. | 248 | @emph{must} use a second @samp{\} to quote it: @samp{?\\}. |
| 249 | 249 | ||
| 250 | @cindex whitespace | 250 | @cindex whitespace |
| 251 | @cindex bell character | 251 | @cindex bell character |
| @@ -336,10 +336,10 @@ outside of strings as well.) | |||
| 336 | 336 | ||
| 337 | The read syntax for meta characters uses @samp{\M-}. For example, | 337 | The read syntax for meta characters uses @samp{\M-}. For example, |
| 338 | @samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with | 338 | @samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with |
| 339 | octal codes, @samp{\C-}, or any other syntax for a character. Thus, you | 339 | octal character codes (see below), with @samp{\C-}, or with any other |
| 340 | can write @kbd{M-A} as @samp{?\M-A}, or as @samp{?\M-\101}. Likewise, | 340 | syntax for a character. Thus, you can write @kbd{M-A} as @samp{?\M-A}, |
| 341 | you can write @kbd{C-M-b} as @samp{?\M-\C-b}, @samp{?\C-\M-b}, or | 341 | or as @samp{?\M-\101}. Likewise, you can write @kbd{C-M-b} as |
| 342 | @samp{?\M-\002}. | 342 | @samp{?\M-\C-b}, @samp{?\C-\M-b}, or @samp{?\M-\002}. |
| 343 | 343 | ||
| 344 | The case of an ordinary letter is indicated by its character code as | 344 | The case of an ordinary letter is indicated by its character code as |
| 345 | part of @sc{ASCII}, but @sc{ASCII} has no way to represent whether a | 345 | part of @sc{ASCII}, but @sc{ASCII} has no way to represent whether a |
| @@ -388,6 +388,74 @@ space, tab, newline and formfeed. However, it is cleaner to use one of | |||
| 388 | the easily readable escape sequences, such as @samp{\t}, instead of an | 388 | the easily readable escape sequences, such as @samp{\t}, instead of an |
| 389 | actual whitespace character such as a tab. | 389 | actual whitespace character such as a tab. |
| 390 | 390 | ||
| 391 | @node Symbol Type | ||
| 392 | @subsection Symbol Type | ||
| 393 | |||
| 394 | A @dfn{symbol} in GNU Emacs Lisp is an object with a name. The symbol | ||
| 395 | name serves as the printed representation of the symbol. In ordinary | ||
| 396 | use, the name is unique---no two symbols have the same name. | ||
| 397 | |||
| 398 | A symbol can serve as a variable, as a function name, or to hold a | ||
| 399 | property list. Or it may serve only to be distinct from all other Lisp | ||
| 400 | objects, so that its presence in a data structure may be recognized | ||
| 401 | reliably. In a given context, usually only one of these uses is | ||
| 402 | intended. But you can use one symbol in all of these ways, | ||
| 403 | independently. | ||
| 404 | |||
| 405 | @cindex @samp{\} in symbols | ||
| 406 | @cindex backslash in symbols | ||
| 407 | A symbol name can contain any characters whatever. Most symbol names | ||
| 408 | are written with letters, digits, and the punctuation characters | ||
| 409 | @samp{-+=*/}. Such names require no special punctuation; the characters | ||
| 410 | of the name suffice as long as the name does not look like a number. | ||
| 411 | (If it does, write a @samp{\} at the beginning of the name to force | ||
| 412 | interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are | ||
| 413 | less often used but also require no special punctuation. Any other | ||
| 414 | characters may be included in a symbol's name by escaping them with a | ||
| 415 | backslash. In contrast to its use in strings, however, a backslash in | ||
| 416 | the name of a symbol simply quotes the single character that follows the | ||
| 417 | backslash. For example, in a string, @samp{\t} represents a tab | ||
| 418 | character; in the name of a symbol, however, @samp{\t} merely quotes the | ||
| 419 | letter @kbd{t}. To have a symbol with a tab character in its name, you | ||
| 420 | must actually use a tab (preceded with a backslash). But it's rare to | ||
| 421 | do such a thing. | ||
| 422 | |||
| 423 | @cindex CL note---case of letters | ||
| 424 | @quotation | ||
| 425 | @b{Common Lisp note:} in Common Lisp, lower case letters are always | ||
| 426 | ``folded'' to upper case, unless they are explicitly escaped. This is | ||
| 427 | in contrast to Emacs Lisp, in which upper case and lower case letters | ||
| 428 | are distinct. | ||
| 429 | @end quotation | ||
| 430 | |||
| 431 | Here are several examples of symbol names. Note that the @samp{+} in | ||
| 432 | the fifth example is escaped to prevent it from being read as a number. | ||
| 433 | This is not necessary in the last example because the rest of the name | ||
| 434 | makes it invalid as a number. | ||
| 435 | |||
| 436 | @example | ||
| 437 | @group | ||
| 438 | foo ; @r{A symbol named @samp{foo}.} | ||
| 439 | FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.} | ||
| 440 | char-to-string ; @r{A symbol named @samp{char-to-string}.} | ||
| 441 | @end group | ||
| 442 | @group | ||
| 443 | 1+ ; @r{A symbol named @samp{1+}} | ||
| 444 | ; @r{(not @samp{+1}, which is an integer).} | ||
| 445 | @end group | ||
| 446 | @group | ||
| 447 | \+1 ; @r{A symbol named @samp{+1}} | ||
| 448 | ; @r{(not a very readable name).} | ||
| 449 | @end group | ||
| 450 | @group | ||
| 451 | \(*\ 1\ 2\) ; @r{A symbol named @samp{(* 1 2)} (a worse name).} | ||
| 452 | @c the @'s in this next line use up three characters, hence the | ||
| 453 | @c apparent misalignment of the comment. | ||
| 454 | +-*/_~!@@$%^&=:<>@{@} ; @r{A symbol named @samp{+-*/_~!@@$%^&=:<>@{@}}.} | ||
| 455 | ; @r{These characters need not be escaped.} | ||
| 456 | @end group | ||
| 457 | @end example | ||
| 458 | |||
| 391 | @node Sequence Type | 459 | @node Sequence Type |
| 392 | @subsection Sequence Types | 460 | @subsection Sequence Types |
| 393 | 461 | ||
| @@ -399,8 +467,9 @@ considered a sequence. | |||
| 399 | Arrays are further subdivided into strings and vectors. Vectors can | 467 | Arrays are further subdivided into strings and vectors. Vectors can |
| 400 | hold elements of any type, but string elements must be characters in the | 468 | hold elements of any type, but string elements must be characters in the |
| 401 | range from 0 to 255. However, the characters in a string can have text | 469 | range from 0 to 255. However, the characters in a string can have text |
| 402 | properties; vectors do not support text properties even when their | 470 | properties like characters in a buffer (@pxref{Text Properties}); |
| 403 | elements happen to be characters. | 471 | vectors do not support text properties even when their elements happen |
| 472 | to be characters. | ||
| 404 | 473 | ||
| 405 | Lists, strings and vectors are different, but they have important | 474 | Lists, strings and vectors are different, but they have important |
| 406 | similarities. For example, all have a length @var{l}, and all have | 475 | similarities. For example, all have a length @var{l}, and all have |
| @@ -416,16 +485,19 @@ sequence twice, you get two sequences with equal contents. There is one | |||
| 416 | exception: the empty list @code{()} always stands for the same object, | 485 | exception: the empty list @code{()} always stands for the same object, |
| 417 | @code{nil}. | 486 | @code{nil}. |
| 418 | 487 | ||
| 419 | @node List Type | 488 | @node Cons Cell Type |
| 420 | @subsection List Type | 489 | @subsection Cons Cell and List Types |
| 421 | @cindex address field of register | 490 | @cindex address field of register |
| 422 | @cindex decrement field of register | 491 | @cindex decrement field of register |
| 423 | 492 | ||
| 424 | A @dfn{list} is a series of cons cells, linked together. A @dfn{cons | 493 | A @dfn{cons cell} is an object comprising two pointers named the |
| 425 | cell} is an object comprising two pointers named the @sc{car} and the | 494 | @sc{car} and the @sc{cdr}. Each of them can point to any Lisp object. |
| 426 | @sc{cdr}. Each of them can point to any Lisp object, but when the cons | 495 | |
| 427 | cell is part of a list, the @sc{cdr} points either to another cons cell | 496 | A @dfn{list} is a series of cons cells, linked together so that the |
| 428 | or to the empty list. @xref{Lists}, for functions that work on lists. | 497 | @sc{cdr} of each cons cell points either to another cons cell or to the |
| 498 | empty list. @xref{Lists}, for functions that work on lists. Because | ||
| 499 | most cons cells are used as part of lists, the phrase @dfn{list | ||
| 500 | structure} has come to refer to any structure made out of cons cells. | ||
| 429 | 501 | ||
| 430 | The names @sc{car} and @sc{cdr} have only historical meaning now. The | 502 | The names @sc{car} and @sc{cdr} have only historical meaning now. The |
| 431 | original Lisp implementation ran on an @w{IBM 704} computer which | 503 | original Lisp implementation ran on an @w{IBM 704} computer which |
| @@ -449,16 +521,16 @@ right parenthesis. | |||
| 449 | Upon reading, each object inside the parentheses becomes an element | 521 | Upon reading, each object inside the parentheses becomes an element |
| 450 | of the list. That is, a cons cell is made for each element. The | 522 | of the list. That is, a cons cell is made for each element. The |
| 451 | @sc{car} of the cons cell points to the element, and its @sc{cdr} points | 523 | @sc{car} of the cons cell points to the element, and its @sc{cdr} points |
| 452 | to the next cons cell which holds the next element in the list. The | 524 | to the next cons cell of the list, which holds the next element in the |
| 453 | @sc{cdr} of the last cons cell is set to point to @code{nil}. | 525 | list. The @sc{cdr} of the last cons cell is set to point to @code{nil}. |
| 454 | 526 | ||
| 455 | @cindex box diagrams, for lists | 527 | @cindex box diagrams, for lists |
| 456 | @cindex diagrams, boxed, for lists | 528 | @cindex diagrams, boxed, for lists |
| 457 | A list can be illustrated by a diagram in which the cons cells are | 529 | A list can be illustrated by a diagram in which the cons cells are |
| 458 | shown as pairs of boxes. (The Lisp reader cannot read such an | 530 | shown as pairs of boxes. (The Lisp reader cannot read such an |
| 459 | illustration; unlike the textual notation, which can be understood both | 531 | illustration; unlike the textual notation, which can be understood by |
| 460 | humans and computers, the box illustrations can only be understood by | 532 | both humans and computers, the box illustrations can be understood only |
| 461 | humans.) The following represents the three-element list @code{(rose | 533 | by humans.) The following represents the three-element list @code{(rose |
| 462 | violet buttercup)}: | 534 | violet buttercup)}: |
| 463 | 535 | ||
| 464 | @example | 536 | @example |
| @@ -642,7 +714,7 @@ functions that work on alists. | |||
| 642 | 714 | ||
| 643 | An @dfn{array} is composed of an arbitrary number of slots for | 715 | An @dfn{array} is composed of an arbitrary number of slots for |
| 644 | referring to other Lisp objects, arranged in a contiguous block of | 716 | referring to other Lisp objects, arranged in a contiguous block of |
| 645 | memory. Accessing any element of an array takes a the same amount of | 717 | memory. Accessing any element of an array takes the same amount of |
| 646 | time. In contrast, accessing an element of a list requires time | 718 | time. In contrast, accessing an element of a list requires time |
| 647 | proportional to the position of the element in the list. (Elements at | 719 | proportional to the position of the element in the list. (Elements at |
| 648 | the end of a list take longer to access than elements at the beginning | 720 | the end of a list take longer to access than elements at the beginning |
| @@ -694,14 +766,20 @@ string constant, this sets the 2**7 bit of the character in the string. | |||
| 694 | This is not the same representation that the meta modifier has in a | 766 | This is not the same representation that the meta modifier has in a |
| 695 | character on its own (not inside a string). @xref{Character Type}. | 767 | character on its own (not inside a string). @xref{Character Type}. |
| 696 | 768 | ||
| 697 | Strings cannot hold characters that have the hyper, super or alt | 769 | Strings cannot hold characters that have the hyper, super, or alt |
| 698 | modifiers; they can hold @sc{ASCII} control characters, but no others. | 770 | modifiers; they can hold @sc{ASCII} control characters, but no others. |
| 699 | They do not distinguish case in @sc{ASCII} control characters. | 771 | They do not distinguish case in @sc{ASCII} control characters. |
| 700 | 772 | ||
| 701 | In contrast with the C programming language, Emacs Lisp allows | 773 | The printed representation of a string consists of a double-quote, the |
| 702 | newlines in string literals. But an escaped newline---one that is | 774 | characters it contains, and another double-quote. However, you must |
| 703 | preceded by @samp{\}---does not become part of the string; i.e., the | 775 | escape any backslash or double-quote characters in the string with a |
| 704 | Lisp reader ignores an escaped newline in a string literal. | 776 | backslash, like this: @code{"this \" is an embedded quote"}. |
| 777 | |||
| 778 | The newline character is not special in the read syntax for strings; | ||
| 779 | if you write a new line between the double-quotes, it becomes a | ||
| 780 | character in the string. But an escaped newline---one that is preceded | ||
| 781 | by @samp{\}---does not become part of the string; i.e., the Lisp reader | ||
| 782 | ignores an escaped newline while reading a string. | ||
| 705 | @cindex newline in strings | 783 | @cindex newline in strings |
| 706 | 784 | ||
| 707 | @example | 785 | @example |
| @@ -714,11 +792,6 @@ in documentation strings, | |||
| 714 | but the newline is ignored if escaped." | 792 | but the newline is ignored if escaped." |
| 715 | @end example | 793 | @end example |
| 716 | 794 | ||
| 717 | The printed representation of a string consists of a double-quote, the | ||
| 718 | characters it contains, and another double-quote. However, any | ||
| 719 | backslash or double-quote characters in the string are preceded with a | ||
| 720 | backslash like this: @code{"this \" is an embedded quote"}. | ||
| 721 | |||
| 722 | A string can hold properties of the text it contains, in addition to | 795 | A string can hold properties of the text it contains, in addition to |
| 723 | the characters themselves. This enables programs that copy text between | 796 | the characters themselves. This enables programs that copy text between |
| 724 | strings and buffers to preserve the properties with no special effort. | 797 | strings and buffers to preserve the properties with no special effort. |
| @@ -764,76 +837,8 @@ for evaluation. | |||
| 764 | 837 | ||
| 765 | @xref{Vectors}, for functions that work with vectors. | 838 | @xref{Vectors}, for functions that work with vectors. |
| 766 | 839 | ||
| 767 | @node Symbol Type | 840 | @node Function Type |
| 768 | @subsection Symbol Type | 841 | @subsection Function Type |
| 769 | |||
| 770 | A @dfn{symbol} in GNU Emacs Lisp is an object with a name. The symbol | ||
| 771 | name serves as the printed representation of the symbol. In ordinary | ||
| 772 | use, the name is unique---no two symbols have the same name. | ||
| 773 | |||
| 774 | A symbol can serve as a variable, as a function name, or to hold a | ||
| 775 | property list. Or it may serve only to be distinct from all other Lisp | ||
| 776 | objects, so that its presence in a data structure may be recognized | ||
| 777 | reliably. In a given context, usually only one of these uses is | ||
| 778 | intended. But you can use one symbol in all of these ways, | ||
| 779 | independently. | ||
| 780 | |||
| 781 | @cindex @samp{\} in symbols | ||
| 782 | @cindex backslash in symbols | ||
| 783 | A symbol name can contain any characters whatever. Most symbol names | ||
| 784 | are written with letters, digits, and the punctuation characters | ||
| 785 | @samp{-+=*/}. Such names require no special punctuation; the characters | ||
| 786 | of the name suffice as long as the name does not look like a number. | ||
| 787 | (If it does, write a @samp{\} at the beginning of the name to force | ||
| 788 | interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are | ||
| 789 | less often used but also require no special punctuation. Any other | ||
| 790 | characters may be included in a symbol's name by escaping them with a | ||
| 791 | backslash. In contrast to its use in strings, however, a backslash in | ||
| 792 | the name of a symbol quotes the single character that follows the | ||
| 793 | backslash, without conversion. For example, in a string, @samp{\t} | ||
| 794 | represents a tab character; in the name of a symbol, however, @samp{\t} | ||
| 795 | merely quotes the letter @kbd{t}. To have a symbol with a tab character | ||
| 796 | in its name, you must actually use a tab (preceded with a backslash). | ||
| 797 | But it's rare to do such a thing. | ||
| 798 | |||
| 799 | @cindex CL note---case of letters | ||
| 800 | @quotation | ||
| 801 | @b{Common Lisp note:} in Common Lisp, lower case letters are always | ||
| 802 | ``folded'' to upper case, unless they are explicitly escaped. This is | ||
| 803 | in contrast to Emacs Lisp, in which upper case and lower case letters | ||
| 804 | are distinct. | ||
| 805 | @end quotation | ||
| 806 | |||
| 807 | Here are several examples of symbol names. Note that the @samp{+} in | ||
| 808 | the fifth example is escaped to prevent it from being read as a number. | ||
| 809 | This is not necessary in the last example because the rest of the name | ||
| 810 | makes it invalid as a number. | ||
| 811 | |||
| 812 | @example | ||
| 813 | @group | ||
| 814 | foo ; @r{A symbol named @samp{foo}.} | ||
| 815 | FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.} | ||
| 816 | char-to-string ; @r{A symbol named @samp{char-to-string}.} | ||
| 817 | @end group | ||
| 818 | @group | ||
| 819 | 1+ ; @r{A symbol named @samp{1+}} | ||
| 820 | ; @r{(not @samp{+1}, which is an integer).} | ||
| 821 | @end group | ||
| 822 | @group | ||
| 823 | \+1 ; @r{A symbol named @samp{+1}} | ||
| 824 | ; @r{(not a very readable name).} | ||
| 825 | @end group | ||
| 826 | @group | ||
| 827 | \(*\ 1\ 2\) ; @r{A symbol named @samp{(* 1 2)} (a worse name).} | ||
| 828 | @c the @'s in this next line use up three characters, hence the | ||
| 829 | @c apparent misalignment of the comment. | ||
| 830 | +-*/_~!@@$%^&=:<>@{@} ; @r{A symbol named @samp{+-*/_~!@@$%^&=:<>@{@}}.} | ||
| 831 | ; @r{These characters need not be escaped.} | ||
| 832 | @end group | ||
| 833 | @end example | ||
| 834 | |||
| 835 | @node Lisp Function Type | ||
| 836 | @subsection Lisp Function Type | ||
| 837 | 842 | ||
| 838 | Just as functions in other programming languages are executable, | 843 | Just as functions in other programming languages are executable, |
| 839 | @dfn{Lisp function} objects are pieces of executable code. However, | 844 | @dfn{Lisp function} objects are pieces of executable code. However, |
| @@ -853,8 +858,8 @@ Lisp expressions in Lisp programs. However, you can construct or obtain | |||
| 853 | a function object at run time and then call it with the primitive | 858 | a function object at run time and then call it with the primitive |
| 854 | functions @code{funcall} and @code{apply}. @xref{Calling Functions}. | 859 | functions @code{funcall} and @code{apply}. @xref{Calling Functions}. |
| 855 | 860 | ||
| 856 | @node Lisp Macro Type | 861 | @node Macro Type |
| 857 | @subsection Lisp Macro Type | 862 | @subsection Macro Type |
| 858 | 863 | ||
| 859 | A @dfn{Lisp macro} is a user-defined construct that extends the Lisp | 864 | A @dfn{Lisp macro} is a user-defined construct that extends the Lisp |
| 860 | language. It is represented as an object much like a function, but with | 865 | language. It is represented as an object much like a function, but with |
| @@ -887,8 +892,8 @@ Calls to the redefined function from Lisp will use the new definition, | |||
| 887 | but calls from C code may still use the built-in definition. | 892 | but calls from C code may still use the built-in definition. |
| 888 | 893 | ||
| 889 | The term @dfn{function} refers to all Emacs functions, whether written | 894 | The term @dfn{function} refers to all Emacs functions, whether written |
| 890 | in Lisp or C. @xref{Lisp Function Type}, for information about the | 895 | in Lisp or C. @xref{Function Type}, for information about the |
| 891 | functions written in Lisp.@refill | 896 | functions written in Lisp. |
| 892 | 897 | ||
| 893 | Primitive functions have no read syntax and print in hash notation | 898 | Primitive functions have no read syntax and print in hash notation |
| 894 | with the name of the subroutine. | 899 | with the name of the subroutine. |
| @@ -977,9 +982,10 @@ object. | |||
| 977 | Each buffer has a designated position called @dfn{point} | 982 | Each buffer has a designated position called @dfn{point} |
| 978 | (@pxref{Positions}). At any time, one buffer is the @dfn{current | 983 | (@pxref{Positions}). At any time, one buffer is the @dfn{current |
| 979 | buffer}. Most editing commands act on the contents of the current | 984 | buffer}. Most editing commands act on the contents of the current |
| 980 | buffer in the neighborhood of point. Many other functions manipulate or | 985 | buffer in the neighborhood of point. Many of the standard Emacs |
| 981 | test the characters in the current buffer; a whole chapter in this | 986 | functions manipulate or test the characters in the current buffer; a |
| 982 | manual is devoted to describing these functions (@pxref{Text}). | 987 | whole chapter in this manual is devoted to describing these functions |
| 988 | (@pxref{Text}). | ||
| 983 | 989 | ||
| 984 | Several other data structures are associated with each buffer: | 990 | Several other data structures are associated with each buffer: |
| 985 | 991 | ||
| @@ -995,7 +1001,7 @@ a local variable binding list (@pxref{Buffer-Local Variables}). | |||
| 995 | @end itemize | 1001 | @end itemize |
| 996 | 1002 | ||
| 997 | @noindent | 1003 | @noindent |
| 998 | The local keymap and variable list contain entries which individually | 1004 | The local keymap and variable list contain entries that individually |
| 999 | override global bindings or values. These are used to customize the | 1005 | override global bindings or values. These are used to customize the |
| 1000 | behavior of programs in different buffers, without actually changing the | 1006 | behavior of programs in different buffers, without actually changing the |
| 1001 | programs. | 1007 | programs. |
| @@ -1144,8 +1150,8 @@ Area}). | |||
| 1144 | Streams have no special printed representation or read syntax, and | 1150 | Streams have no special printed representation or read syntax, and |
| 1145 | print as whatever primitive type they are. | 1151 | print as whatever primitive type they are. |
| 1146 | 1152 | ||
| 1147 | @xref{Streams}, for a description of various functions related to | 1153 | @xref{Streams, Reading and Printing}, for a description of functions |
| 1148 | streams, including various parsing and printing functions. | 1154 | related to streams, including parsing and printing functions. |
| 1149 | 1155 | ||
| 1150 | @node Keymap Type | 1156 | @node Keymap Type |
| 1151 | @subsection Keymap Type | 1157 | @subsection Keymap Type |
| @@ -1167,7 +1173,7 @@ character is punctuation, but in Lisp mode it is a valid character in a | |||
| 1167 | symbol. These modes specify different interpretations by changing the | 1173 | symbol. These modes specify different interpretations by changing the |
| 1168 | syntax table entry for @samp{+}, at index 43 in the syntax table. | 1174 | syntax table entry for @samp{+}, at index 43 in the syntax table. |
| 1169 | 1175 | ||
| 1170 | Syntax tables are only used for scanning text in buffers, not for | 1176 | Syntax tables are used only for scanning text in buffers, not for |
| 1171 | reading Lisp expressions. The table the Lisp interpreter uses to read | 1177 | reading Lisp expressions. The table the Lisp interpreter uses to read |
| 1172 | expressions is built into the Emacs source code and cannot be changed; | 1178 | expressions is built into the Emacs source code and cannot be changed; |
| 1173 | thus, to change the list delimiters to be @samp{@{} and @samp{@}} | 1179 | thus, to change the list delimiters to be @samp{@{} and @samp{@}} |
| @@ -1212,7 +1218,7 @@ a type that the function can use. | |||
| 1212 | All built-in functions do check the types of their actual arguments | 1218 | All built-in functions do check the types of their actual arguments |
| 1213 | when appropriate, and signal a @code{wrong-type-argument} error if an | 1219 | when appropriate, and signal a @code{wrong-type-argument} error if an |
| 1214 | argument is of the wrong type. For example, here is what happens if you | 1220 | argument is of the wrong type. For example, here is what happens if you |
| 1215 | pass an argument to @code{+} which it cannot handle: | 1221 | pass an argument to @code{+} that it cannot handle: |
| 1216 | 1222 | ||
| 1217 | @example | 1223 | @example |
| 1218 | @group | 1224 | @group |
| @@ -1279,8 +1285,8 @@ with references to further information. | |||
| 1279 | @item markerp | 1285 | @item markerp |
| 1280 | @xref{Predicates on Markers, markerp}. | 1286 | @xref{Predicates on Markers, markerp}. |
| 1281 | 1287 | ||
| 1282 | @item natnump | 1288 | @item wholenump |
| 1283 | @xref{Predicates on Numbers, natnump}. | 1289 | @xref{Predicates on Numbers, wholenump}. |
| 1284 | 1290 | ||
| 1285 | @item nlistp | 1291 | @item nlistp |
| 1286 | @xref{List-related Predicates, nlistp}. | 1292 | @xref{List-related Predicates, nlistp}. |
| @@ -1334,8 +1340,8 @@ with references to further information. | |||
| 1334 | 1340 | ||
| 1335 | Here we describe two functions that test for equality between any two | 1341 | Here we describe two functions that test for equality between any two |
| 1336 | objects. Other functions test equality between objects of specific | 1342 | objects. Other functions test equality between objects of specific |
| 1337 | types, e.g., strings. See the appropriate chapter describing the data | 1343 | types, e.g., strings. For these predicates, see the appropriate chapter |
| 1338 | type for these predicates. | 1344 | describing the data type. |
| 1339 | 1345 | ||
| 1340 | @defun eq object1 object2 | 1346 | @defun eq object1 object2 |
| 1341 | This function returns @code{t} if @var{object1} and @var{object2} are | 1347 | This function returns @code{t} if @var{object1} and @var{object2} are |
diff --git a/lispref/symbols.texi b/lispref/symbols.texi index 39f1bbcb80c..7d7825d88fc 100644 --- a/lispref/symbols.texi +++ b/lispref/symbols.texi | |||
| @@ -41,7 +41,7 @@ references another object: | |||
| 41 | @table @asis | 41 | @table @asis |
| 42 | @item Print name | 42 | @item Print name |
| 43 | @cindex print name cell | 43 | @cindex print name cell |
| 44 | The @dfn{print name cell} holds a string which names the symbol for | 44 | The @dfn{print name cell} holds a string that names the symbol for |
| 45 | reading and printing. See @code{symbol-name} in @ref{Creating Symbols}. | 45 | reading and printing. See @code{symbol-name} in @ref{Creating Symbols}. |
| 46 | 46 | ||
| 47 | @item Value | 47 | @item Value |
| @@ -93,7 +93,7 @@ to see a property list there. | |||
| 93 | The function cell or the value cell may be @dfn{void}, which means | 93 | The function cell or the value cell may be @dfn{void}, which means |
| 94 | that the cell does not reference any object. (This is not the same | 94 | that the cell does not reference any object. (This is not the same |
| 95 | thing as holding the symbol @code{void}, nor the same as holding the | 95 | thing as holding the symbol @code{void}, nor the same as holding the |
| 96 | symbol @code{nil}.) Examining a cell which is void results in an error, | 96 | symbol @code{nil}.) Examining a cell that is void results in an error, |
| 97 | such as @samp{Symbol's value as variable is void}. | 97 | such as @samp{Symbol's value as variable is void}. |
| 98 | 98 | ||
| 99 | The four functions @code{symbol-name}, @code{symbol-value}, | 99 | The four functions @code{symbol-name}, @code{symbol-value}, |
| @@ -194,18 +194,24 @@ given hash code; to look for a given name, it is sufficient to look | |||
| 194 | through all the symbols in the bucket for that name's hash code. | 194 | through all the symbols in the bucket for that name's hash code. |
| 195 | 195 | ||
| 196 | @cindex interning | 196 | @cindex interning |
| 197 | If a symbol with the desired name is found, then it is used. If no | 197 | If a symbol with the desired name is found, the reader uses that |
| 198 | such symbol is found, then a new symbol is created and added to the | 198 | symbol. If the obarray does not contain a symbol with that name, the |
| 199 | obarray bucket. Adding a symbol to an obarray is called @dfn{interning} | 199 | reader makes a new symbol and adds it to the obarray. Finding or adding |
| 200 | it, and the symbol is then called an @dfn{interned symbol}. | 200 | a symbol with a certain name is called @dfn{interning} it, and the |
| 201 | symbol is then called an @dfn{interned symbol}. | ||
| 202 | |||
| 203 | Interning ensures that each obarray has just one symbol with any | ||
| 204 | particular name. Other like-named symbols may exist, but not in the | ||
| 205 | same obarray. Thus, the reader gets the same symbols for the same | ||
| 206 | names, as long as you keep reading with the same obarray. | ||
| 201 | 207 | ||
| 202 | @cindex symbol equality | 208 | @cindex symbol equality |
| 203 | @cindex uninterned symbol | 209 | @cindex uninterned symbol |
| 204 | If a symbol is not in the obarray, then there is no way for Lisp to | 210 | No obarray contains all symbols; in fact, some symbols are not in any |
| 205 | find it when its name is read. Such a symbol is called an | 211 | obarray. They are called @dfn{uninterned symbols}. An uninterned |
| 206 | @dfn{uninterned symbol} relative to the obarray. An uninterned symbol | 212 | symbol has the same four cells as other symbols; however, the only way |
| 207 | has all the other characteristics of interned symbols; it has the same | 213 | to gain access to it is by finding it in some other object or as the |
| 208 | four cells and they work in the usual way. | 214 | value of a variable. |
| 209 | 215 | ||
| 210 | In Emacs Lisp, an obarray is actually a vector. Each element of the | 216 | In Emacs Lisp, an obarray is actually a vector. Each element of the |
| 211 | vector is a bucket; its value is either an interned symbol whose name | 217 | vector is a bucket; its value is either an interned symbol whose name |
| @@ -323,7 +329,7 @@ This variable is the standard obarray for use by @code{intern} and | |||
| 323 | @end defvar | 329 | @end defvar |
| 324 | 330 | ||
| 325 | @defun mapatoms function &optional obarray | 331 | @defun mapatoms function &optional obarray |
| 326 | This function call @var{function} for each symbol in the obarray | 332 | This function calls @var{function} for each symbol in the obarray |
| 327 | @var{obarray}. It returns @code{nil}. If @var{obarray} is omitted, it | 333 | @var{obarray}. It returns @code{nil}. If @var{obarray} is omitted, it |
| 328 | defaults to the value of @code{obarray}, the standard obarray for | 334 | defaults to the value of @code{obarray}, the standard obarray for |
| 329 | ordinary symbols. | 335 | ordinary symbols. |
| @@ -353,9 +359,9 @@ example using @code{mapatoms}. | |||
| 353 | elements stored in the property list cell of a symbol. Each of the | 359 | elements stored in the property list cell of a symbol. Each of the |
| 354 | pairs associates a property name (usually a symbol) with a property or | 360 | pairs associates a property name (usually a symbol) with a property or |
| 355 | value. Property lists are generally used to record information about a | 361 | value. Property lists are generally used to record information about a |
| 356 | symbol, such as how to compile it, the name of the file where it was | 362 | symbol, such as its documentation as a variable, the name of the file |
| 357 | defined, or perhaps even the grammatical class of the symbol | 363 | where it was defined, or perhaps even the grammatical class of the |
| 358 | (representing a word) in a language understanding system. | 364 | symbol (representing a word) in a language-understanding system. |
| 359 | 365 | ||
| 360 | Character positions in a string or buffer can also have property lists. | 366 | Character positions in a string or buffer can also have property lists. |
| 361 | @xref{Text Properties}. | 367 | @xref{Text Properties}. |