aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-26 22:08:09 +0000
committerRichard M. Stallman1994-04-26 22:08:09 +0000
commit2b3fc6c3053c124f9f128152d9456bfe90151cc6 (patch)
tree118d88a3734cecba17e9bf04d75373c6356f76ac
parenta1a7207a13168b6231e46ee44b39c661fd0c6128 (diff)
downloademacs-2b3fc6c3053c124f9f128152d9456bfe90151cc6.tar.gz
emacs-2b3fc6c3053c124f9f128152d9456bfe90151cc6.zip
*** empty log message ***
-rw-r--r--lispref/lists.texi160
-rw-r--r--lispref/objects.texi254
-rw-r--r--lispref/symbols.texi36
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
35pair. It records two Lisp objects, one labeled as the @sc{car}, and the 35ordered pair. It records two Lisp objects, one labeled as the @sc{car},
36other labeled as the @sc{cdr}. These names are traditional; @sc{cdr} is 36and the other labeled as the @sc{cdr}. These names are traditional; see
37pronounced ``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
40element of the list. By convention, the @sc{car}s of the cons cells are 40element 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
45level of cons cells, the @sc{car} and @sc{cdr} slots have the same 45level of cons cells, the @sc{car} and @sc{cdr} slots have the same
46characteristics. 46characteristics.
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
51cells.
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
49the list with no elements. For convenience, the symbol @code{nil} is 54the list with no elements. For convenience, the symbol @code{nil} is
50considered to have @code{nil} as its @sc{cdr} (and also as its 55considered 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. 143lists, 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.
155This function returns @code{t} if @var{object} is an atom, @code{nil} 160This function returns @code{t} if @var{object} is an atom, @code{nil}
156otherwise. All objects except cons cells are atoms. The symbol 161otherwise. 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
158which is both. 163that 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
435This function returns a list containing all the elements of 440This 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,
437All arguments except the last one are copied, so none of them are 442but the last one should be a list. All arguments except the last one
438altered. 443are copied, so none of them are altered.
444
445More generally, the final argument to @code{append} may be any Lisp
446object. 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
448is itself a list, then its elements become in effect elements of the
449result 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
451in a true list.
439 452
440 The final argument to @code{append} may be any object but it is 453See @code{nconc} in @ref{Rearrangement}, for a way to join lists with no
441typically a list. The final argument is not copied or converted; it 454copying.
442becomes part of the structure of the new list.
443 455
444 Here is an example: 456Here 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
466You can see what happens by looking at a box diagram. The variable 478You 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 479variable @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)}. 480variable @code{more-trees} is set to the list @code{(maple birch pine
469However, the variable @code{trees} continues to refer to the original 481oak)}. However, the variable @code{trees} continues to refer to the
470list: 482original 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
530See @code{nconc} in @ref{Rearrangement}, for a way to join lists with no 542Here are some examples where the final argument is not a list:
531copying. 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
552The second example shows that when the final argument is a sequence but
553not a list, the sequence's elements do not become elements of the
554resulting list. Instead, the sequence becomes the final @sc{cdr}, like
555any other non-list final argument.
532 556
533Integers are also allowed as arguments to @code{append}. They are 557Integers are also allowed as arguments to @code{append}. They are
534converted to strings of digits making up the decimal print 558converted 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
610replaces one element of a list with a different element. 634used on a list, @code{setcar} replaces one element of a list with a
635different element.
611 636
612@defun setcar cons object 637@defun setcar cons object
613This function stores @var{object} as the new @sc{car} of @var{cons}, 638This 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
713This function stores @var{object} into the @sc{cdr} of @var{cons}. The 738This function stores @var{object} as the new @sc{cdr} of @var{cons},
714value returned is @var{object}, not @var{cons}. 739replacing 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
813functions ``destructive'' because they chew up the original lists passed 838functions ``destructive'' because they chew up the original lists passed
814to them as arguments, to produce a new list that is the returned value. 839to 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
843that modifies cons cells.
844@end ifinfo
845@iftex
846 The function @code{delq} in the following section is another example
847of 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}.
898Unlike @code{reverse}, @code{nreverse} alters its argument destructively 932Unlike @code{reverse}, @code{nreverse} alters its argument by reversing
899by reversing the @sc{cdr}s in the cons cells forming the list. The cons 933the @sc{cdr}s in the cons cells forming the list. The cons cell that
900cell which used to be the last one in @var{list} becomes the first cell 934used to be the last one in @var{list} becomes the first cell of the
901of the value. 935value.
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
966original, copy it first with @code{copy-sequence} and then sort. 1000original, copy it first with @code{copy-sequence} and then sort.
967 1001
968Sorting does not change the @sc{car}s of the cons cells in @var{list}; 1002Sorting does not change the @sc{car}s of the cons cells in @var{list};
1003each cons cell in the result contains the same element that it contained
1004before. The result differs from the argument @var{list} because the
1005cells themselves have been reordered.
1006
1007Sorting does not change the @sc{car}s of the cons cells in @var{list};
969the cons cell that originally contained the element @code{a} in 1008the 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
971appears in a different position in the list due to the change of 1010appears 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
1003useful example of @code{sort}. 1042useful 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
1008that modifies cons cells.
1009@end ifinfo
1010@iftex
1011 The function @code{delq} in the following section is another example
1012of 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
1086sample-list 1116sample-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
1094sample-list 1124sample-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
1099Note that @code{(delq 2 sample-list)} modifies @code{sample-list} to 1129Note that @code{(delq 'b sample-list)} modifies @code{sample-list} to
1100splice out the second element, but @code{(delq 1 sample-list)} does not 1130splice out the second element, but @code{(delq 'a sample-list)} does not
1101splice anything---it just returns a shorter list. Don't assume that a 1131splice anything---it just returns a shorter list. Don't assume that a
1102variable which formerly held the argument @var{list} now has fewer 1132variable which formerly held the argument @var{list} now has fewer
1103elements, or that it still holds the original list! Instead, save the 1133elements, 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
1261Here is another example in which the keys and values are not symbols: 1291Here 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
1414the 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
41variable, and the type is known by the compiler but not represented in 41variable, and the type is known by the compiler but not represented in
42the data. Such type declarations do not exist in Emacs Lisp. A Lisp 42the data. Such type declarations do not exist in Emacs Lisp. A Lisp
43variable can have any type of value, and remembers the type of any value 43variable can have any type of value, and it remembers whatever value
44you store in it. 44you 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
47syntax of each of the standard types in GNU Emacs Lisp. Details on how 47syntax 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
170overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit 170overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit
171implementations.@refill 171implementations.@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
174optional sign at the beginning and an optional period at the end. The 174optional sign at the beginning and an optional period at the end. The
175printed representation produced by the Lisp interpreter never has a 175printed representation produced by the Lisp interpreter never has a
176leading @samp{+} or a final @samp{.}. 176leading @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
245often a good idea to add a @samp{\} to prevent Lisp mode from getting 245often a good idea to add a @samp{\} so that the Emacs commands for
246confused. For example, @samp{?\ } is the way to write the space 246editing Lisp code don't get confused. For example, @samp{?\ } is the
247character. If the character is @samp{\}, you @emph{must} use a second 247way 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
339octal codes, @samp{\C-}, or any other syntax for a character. Thus, you 339octal character codes (see below), with @samp{\C-}, or with any other
340can write @kbd{M-A} as @samp{?\M-A}, or as @samp{?\M-\101}. Likewise, 340syntax for a character. Thus, you can write @kbd{M-A} as @samp{?\M-A},
341you can write @kbd{C-M-b} as @samp{?\M-\C-b}, @samp{?\C-\M-b}, or 341or 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
345part of @sc{ASCII}, but @sc{ASCII} has no way to represent whether a 345part 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
388the easily readable escape sequences, such as @samp{\t}, instead of an 388the easily readable escape sequences, such as @samp{\t}, instead of an
389actual whitespace character such as a tab. 389actual 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
395name serves as the printed representation of the symbol. In ordinary
396use, 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
399property list. Or it may serve only to be distinct from all other Lisp
400objects, so that its presence in a data structure may be recognized
401reliably. In a given context, usually only one of these uses is
402intended. But you can use one symbol in all of these ways,
403independently.
404
405@cindex @samp{\} in symbols
406@cindex backslash in symbols
407 A symbol name can contain any characters whatever. Most symbol names
408are written with letters, digits, and the punctuation characters
409@samp{-+=*/}. Such names require no special punctuation; the characters
410of 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
412interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are
413less often used but also require no special punctuation. Any other
414characters may be included in a symbol's name by escaping them with a
415backslash. In contrast to its use in strings, however, a backslash in
416the name of a symbol simply quotes the single character that follows the
417backslash. For example, in a string, @samp{\t} represents a tab
418character; in the name of a symbol, however, @samp{\t} merely quotes the
419letter @kbd{t}. To have a symbol with a tab character in its name, you
420must actually use a tab (preceded with a backslash). But it's rare to
421do 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
427in contrast to Emacs Lisp, in which upper case and lower case letters
428are distinct.
429@end quotation
430
431 Here are several examples of symbol names. Note that the @samp{+} in
432the fifth example is escaped to prevent it from being read as a number.
433This is not necessary in the last example because the rest of the name
434makes it invalid as a number.
435
436@example
437@group
438foo ; @r{A symbol named @samp{foo}.}
439FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.}
440char-to-string ; @r{A symbol named @samp{char-to-string}.}
441@end group
442@group
4431+ ; @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
400hold elements of any type, but string elements must be characters in the 468hold elements of any type, but string elements must be characters in the
401range from 0 to 255. However, the characters in a string can have text 469range from 0 to 255. However, the characters in a string can have text
402properties; vectors do not support text properties even when their 470properties like characters in a buffer (@pxref{Text Properties});
403elements happen to be characters. 471vectors do not support text properties even when their elements happen
472to 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
406similarities. For example, all have a length @var{l}, and all have 475similarities. 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
416exception: the empty list @code{()} always stands for the same object, 485exception: 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
425cell} 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
427cell 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
428or 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
498empty list. @xref{Lists}, for functions that work on lists. Because
499most cons cells are used as part of lists, the phrase @dfn{list
500structure} 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
431original Lisp implementation ran on an @w{IBM 704} computer which 503original 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
450of the list. That is, a cons cell is made for each element. The 522of 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
452to the next cons cell which holds the next element in the list. The 524to 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}. 525list. 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
458shown as pairs of boxes. (The Lisp reader cannot read such an 530shown as pairs of boxes. (The Lisp reader cannot read such an
459illustration; unlike the textual notation, which can be understood both 531illustration; unlike the textual notation, which can be understood by
460humans and computers, the box illustrations can only be understood by 532both humans and computers, the box illustrations can be understood only
461humans.) The following represents the three-element list @code{(rose 533by humans.) The following represents the three-element list @code{(rose
462violet buttercup)}: 534violet 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
644referring to other Lisp objects, arranged in a contiguous block of 716referring to other Lisp objects, arranged in a contiguous block of
645memory. Accessing any element of an array takes a the same amount of 717memory. Accessing any element of an array takes the same amount of
646time. In contrast, accessing an element of a list requires time 718time. In contrast, accessing an element of a list requires time
647proportional to the position of the element in the list. (Elements at 719proportional to the position of the element in the list. (Elements at
648the end of a list take longer to access than elements at the beginning 720the 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.
694This is not the same representation that the meta modifier has in a 766This is not the same representation that the meta modifier has in a
695character on its own (not inside a string). @xref{Character Type}. 767character 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
698modifiers; they can hold @sc{ASCII} control characters, but no others. 770modifiers; they can hold @sc{ASCII} control characters, but no others.
699They do not distinguish case in @sc{ASCII} control characters. 771They 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
702newlines in string literals. But an escaped newline---one that is 774characters it contains, and another double-quote. However, you must
703preceded by @samp{\}---does not become part of the string; i.e., the 775escape any backslash or double-quote characters in the string with a
704Lisp reader ignores an escaped newline in a string literal. 776backslash, like this: @code{"this \" is an embedded quote"}.
777
778 The newline character is not special in the read syntax for strings;
779if you write a new line between the double-quotes, it becomes a
780character in the string. But an escaped newline---one that is preceded
781by @samp{\}---does not become part of the string; i.e., the Lisp reader
782ignores 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,
714but the newline is ignored if escaped." 792but 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
718characters it contains, and another double-quote. However, any
719backslash or double-quote characters in the string are preceded with a
720backslash 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
723the characters themselves. This enables programs that copy text between 796the characters themselves. This enables programs that copy text between
724strings and buffers to preserve the properties with no special effort. 797strings 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
771name serves as the printed representation of the symbol. In ordinary
772use, 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
775property list. Or it may serve only to be distinct from all other Lisp
776objects, so that its presence in a data structure may be recognized
777reliably. In a given context, usually only one of these uses is
778intended. But you can use one symbol in all of these ways,
779independently.
780
781@cindex @samp{\} in symbols
782@cindex backslash in symbols
783 A symbol name can contain any characters whatever. Most symbol names
784are written with letters, digits, and the punctuation characters
785@samp{-+=*/}. Such names require no special punctuation; the characters
786of 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
788interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are
789less often used but also require no special punctuation. Any other
790characters may be included in a symbol's name by escaping them with a
791backslash. In contrast to its use in strings, however, a backslash in
792the name of a symbol quotes the single character that follows the
793backslash, without conversion. For example, in a string, @samp{\t}
794represents a tab character; in the name of a symbol, however, @samp{\t}
795merely quotes the letter @kbd{t}. To have a symbol with a tab character
796in its name, you must actually use a tab (preceded with a backslash).
797But 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
803in contrast to Emacs Lisp, in which upper case and lower case letters
804are distinct.
805@end quotation
806
807 Here are several examples of symbol names. Note that the @samp{+} in
808the fifth example is escaped to prevent it from being read as a number.
809This is not necessary in the last example because the rest of the name
810makes it invalid as a number.
811
812@example
813@group
814foo ; @r{A symbol named @samp{foo}.}
815FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.}
816char-to-string ; @r{A symbol named @samp{char-to-string}.}
817@end group
818@group
8191+ ; @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
853a function object at run time and then call it with the primitive 858a function object at run time and then call it with the primitive
854functions @code{funcall} and @code{apply}. @xref{Calling Functions}. 859functions @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
860language. It is represented as an object much like a function, but with 865language. 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,
887but calls from C code may still use the built-in definition. 892but 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
890in Lisp or C. @xref{Lisp Function Type}, for information about the 895in Lisp or C. @xref{Function Type}, for information about the
891functions written in Lisp.@refill 896functions 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
894with the name of the subroutine. 899with 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
979buffer}. Most editing commands act on the contents of the current 984buffer}. Most editing commands act on the contents of the current
980buffer in the neighborhood of point. Many other functions manipulate or 985buffer in the neighborhood of point. Many of the standard Emacs
981test the characters in the current buffer; a whole chapter in this 986functions manipulate or test the characters in the current buffer; a
982manual is devoted to describing these functions (@pxref{Text}). 987whole 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
998The local keymap and variable list contain entries which individually 1004The local keymap and variable list contain entries that individually
999override global bindings or values. These are used to customize the 1005override global bindings or values. These are used to customize the
1000behavior of programs in different buffers, without actually changing the 1006behavior of programs in different buffers, without actually changing the
1001programs. 1007programs.
@@ -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
1145print as whatever primitive type they are. 1151print 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
1148streams, including various parsing and printing functions. 1154related 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
1167symbol. These modes specify different interpretations by changing the 1173symbol. These modes specify different interpretations by changing the
1168syntax table entry for @samp{+}, at index 43 in the syntax table. 1174syntax 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
1171reading Lisp expressions. The table the Lisp interpreter uses to read 1177reading Lisp expressions. The table the Lisp interpreter uses to read
1172expressions is built into the Emacs source code and cannot be changed; 1178expressions is built into the Emacs source code and cannot be changed;
1173thus, to change the list delimiters to be @samp{@{} and @samp{@}} 1179thus, 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
1213when appropriate, and signal a @code{wrong-type-argument} error if an 1219when appropriate, and signal a @code{wrong-type-argument} error if an
1214argument is of the wrong type. For example, here is what happens if you 1220argument is of the wrong type. For example, here is what happens if you
1215pass an argument to @code{+} which it cannot handle: 1221pass 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
1336objects. Other functions test equality between objects of specific 1342objects. Other functions test equality between objects of specific
1337types, e.g., strings. See the appropriate chapter describing the data 1343types, e.g., strings. For these predicates, see the appropriate chapter
1338type for these predicates. 1344describing the data type.
1339 1345
1340@defun eq object1 object2 1346@defun eq object1 object2
1341This function returns @code{t} if @var{object1} and @var{object2} are 1347This 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
44The @dfn{print name cell} holds a string which names the symbol for 44The @dfn{print name cell} holds a string that names the symbol for
45reading and printing. See @code{symbol-name} in @ref{Creating Symbols}. 45reading 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
94that the cell does not reference any object. (This is not the same 94that the cell does not reference any object. (This is not the same
95thing as holding the symbol @code{void}, nor the same as holding the 95thing as holding the symbol @code{void}, nor the same as holding the
96symbol @code{nil}.) Examining a cell which is void results in an error, 96symbol @code{nil}.) Examining a cell that is void results in an error,
97such as @samp{Symbol's value as variable is void}. 97such 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
194through all the symbols in the bucket for that name's hash code. 194through 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
198such symbol is found, then a new symbol is created and added to the 198symbol. If the obarray does not contain a symbol with that name, the
199obarray bucket. Adding a symbol to an obarray is called @dfn{interning} 199reader makes a new symbol and adds it to the obarray. Finding or adding
200it, and the symbol is then called an @dfn{interned symbol}. 200a symbol with a certain name is called @dfn{interning} it, and the
201symbol is then called an @dfn{interned symbol}.
202
203 Interning ensures that each obarray has just one symbol with any
204particular name. Other like-named symbols may exist, but not in the
205same obarray. Thus, the reader gets the same symbols for the same
206names, 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
205find it when its name is read. Such a symbol is called an 211obarray. They are called @dfn{uninterned symbols}. An uninterned
206@dfn{uninterned symbol} relative to the obarray. An uninterned symbol 212symbol has the same four cells as other symbols; however, the only way
207has all the other characteristics of interned symbols; it has the same 213to gain access to it is by finding it in some other object or as the
208four cells and they work in the usual way. 214value 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
211vector is a bucket; its value is either an interned symbol whose name 217vector 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
326This function call @var{function} for each symbol in the obarray 332This 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
328defaults to the value of @code{obarray}, the standard obarray for 334defaults to the value of @code{obarray}, the standard obarray for
329ordinary symbols. 335ordinary symbols.
@@ -353,9 +359,9 @@ example using @code{mapatoms}.
353elements stored in the property list cell of a symbol. Each of the 359elements stored in the property list cell of a symbol. Each of the
354pairs associates a property name (usually a symbol) with a property or 360pairs associates a property name (usually a symbol) with a property or
355value. Property lists are generally used to record information about a 361value. Property lists are generally used to record information about a
356symbol, such as how to compile it, the name of the file where it was 362symbol, such as its documentation as a variable, the name of the file
357defined, or perhaps even the grammatical class of the symbol 363where it was defined, or perhaps even the grammatical class of the
358(representing a word) in a language understanding system. 364symbol (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}.