aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/objects.texi
diff options
context:
space:
mode:
authorRichard M. Stallman1999-09-17 06:59:04 +0000
committerRichard M. Stallman1999-09-17 06:59:04 +0000
commit8241495da57ca0efed1b2e86ff693b5614e0aebd (patch)
treeee1fca7ca3eafe24dbbf651622196bc849203e69 /lispref/objects.texi
parent106217c6600b3049f1c62afaf198b9382206acba (diff)
downloademacs-8241495da57ca0efed1b2e86ff693b5614e0aebd.tar.gz
emacs-8241495da57ca0efed1b2e86ff693b5614e0aebd.zip
*** empty log message ***
Diffstat (limited to 'lispref/objects.texi')
-rw-r--r--lispref/objects.texi161
1 files changed, 123 insertions, 38 deletions
diff --git a/lispref/objects.texi b/lispref/objects.texi
index fcd50f3c1e9..7a70f4417ac 100644
--- a/lispref/objects.texi
+++ b/lispref/objects.texi
@@ -25,7 +25,7 @@ but not for ``the'' type of an object.
25which all other types are constructed, are called @dfn{primitive 25which all other types are constructed, are called @dfn{primitive
26types}. Each object belongs to one and only one primitive type. These 26types}. Each object belongs to one and only one primitive type. These
27types include @dfn{integer}, @dfn{float}, @dfn{cons}, @dfn{symbol}, 27types include @dfn{integer}, @dfn{float}, @dfn{cons}, @dfn{symbol},
28@dfn{string}, @dfn{vector}, @dfn{subr}, @dfn{byte-code function}, plus 28@dfn{string}, @dfn{vector}, @dfn{subr}, and @dfn{byte-code function}, plus
29several special types, such as @dfn{buffer}, that are related to 29several special types, such as @dfn{buffer}, that are related to
30editing. (@xref{Editing Types}.) 30editing. (@xref{Editing Types}.)
31 31
@@ -52,6 +52,7 @@ to use these types can be found in later chapters.
52* Comments:: Comments and their formatting conventions. 52* Comments:: Comments and their formatting conventions.
53* Programming Types:: Types found in all Lisp systems. 53* Programming Types:: Types found in all Lisp systems.
54* Editing Types:: Types specific to Emacs. 54* Editing Types:: Types specific to Emacs.
55* Circular Objects:: Read syntax for circular structure.
55* Type Predicates:: Tests related to types. 56* Type Predicates:: Tests related to types.
56* Equality Predicates:: Tests of equality between any two objects. 57* Equality Predicates:: Tests of equality between any two objects.
57@end menu 58@end menu
@@ -146,6 +147,7 @@ latter are unique to Emacs Lisp.
146* Vector Type:: One-dimensional arrays. 147* Vector Type:: One-dimensional arrays.
147* Char-Table Type:: One-dimensional sparse arrays indexed by characters. 148* Char-Table Type:: One-dimensional sparse arrays indexed by characters.
148* Bool-Vector Type:: One-dimensional arrays of @code{t} or @code{nil}. 149* Bool-Vector Type:: One-dimensional arrays of @code{t} or @code{nil}.
150* Hash Table Type:: Super-fast lookup tables.
149* Function Type:: A piece of executable code you can call from elsewhere. 151* Function Type:: A piece of executable code you can call from elsewhere.
150* Macro Type:: A method of expanding an expression into another 152* Macro Type:: A method of expanding an expression into another
151 expression, more fundamental but less pretty. 153 expression, more fundamental but less pretty.
@@ -164,14 +166,14 @@ latter are unique to Emacs Lisp.
164-2**27 166-2**27
165@end ifinfo 167@end ifinfo
166@tex 168@tex
167$-2^{27}$ 169@math{-2^{27}}
168@end tex 170@end tex
169to 171to
170@ifinfo 172@ifinfo
1712**27 - 1) 1732**27 - 1)
172@end ifinfo 174@end ifinfo
173@tex 175@tex
174$2^{28}-1$) 176@math{2^{28}-1})
175@end tex 177@end tex
176on most machines. (Some machines may provide a wider range.) It is 178on most machines. (Some machines may provide a wider range.) It is
177important to note that the Emacs Lisp arithmetic functions do not check 179important to note that the Emacs Lisp arithmetic functions do not check
@@ -187,7 +189,7 @@ leading @samp{+} or a final @samp{.}.
187@group 189@group
188-1 ; @r{The integer -1.} 190-1 ; @r{The integer -1.}
1891 ; @r{The integer 1.} 1911 ; @r{The integer 1.}
1901. ; @r{Also The integer 1.} 1921. ; @r{Also the integer 1.}
191+1 ; @r{Also the integer 1.} 193+1 ; @r{Also the integer 1.}
192268435457 ; @r{Also the integer 1 on a 28-bit implementation.} 194268435457 ; @r{Also the integer 1 on a 28-bit implementation.}
193@end group 195@end group
@@ -212,7 +214,7 @@ number whose value is 1500. They are all equivalent.
212 214
213@node Character Type 215@node Character Type
214@subsection Character Type 216@subsection Character Type
215@cindex @sc{ASCII} character codes 217@cindex @sc{ascii} character codes
216 218
217 A @dfn{character} in Emacs Lisp is nothing more than an integer. In 219 A @dfn{character} in Emacs Lisp is nothing more than an integer. In
218other words, characters are represented by their character codes. For 220other words, characters are represented by their character codes. For
@@ -290,6 +292,7 @@ respectively. Thus,
290?\r @result{} 13 ; @r{carriage return, @key{RET}, @kbd{C-m}} 292?\r @result{} 13 ; @r{carriage return, @key{RET}, @kbd{C-m}}
291?\e @result{} 27 ; @r{escape character, @key{ESC}, @kbd{C-[}} 293?\e @result{} 27 ; @r{escape character, @key{ESC}, @kbd{C-[}}
292?\\ @result{} 92 ; @r{backslash character, @kbd{\}} 294?\\ @result{} 92 ; @r{backslash character, @kbd{\}}
295?\d @result{} 127 ; @r{delete character, @key{DEL}}
293@end example 296@end example
294 297
295@cindex escape sequence 298@cindex escape sequence
@@ -312,17 +315,17 @@ equivalent to @samp{?\^I} and to @samp{?\^i}:
312@end example 315@end example
313 316
314 In strings and buffers, the only control characters allowed are those 317 In strings and buffers, the only control characters allowed are those
315that exist in @sc{ASCII}; but for keyboard input purposes, you can turn 318that exist in @sc{ascii}; but for keyboard input purposes, you can turn
316any character into a control character with @samp{C-}. The character 319any character into a control character with @samp{C-}. The character
317codes for these non-@sc{ASCII} control characters include the 320codes for these non-@sc{ascii} control characters include the
318@tex 321@tex
319$2^{26}$ 322@math{2^{26}}
320@end tex 323@end tex
321@ifinfo 324@ifinfo
3222**26 3252**26
323@end ifinfo 326@end ifinfo
324bit as well as the code for the corresponding non-control 327bit as well as the code for the corresponding non-control
325character. Ordinary terminals have no way of generating non-@sc{ASCII} 328character. Ordinary terminals have no way of generating non-@sc{ascii}
326control characters, but you can generate them straightforwardly using X 329control characters, but you can generate them straightforwardly using X
327and other window systems. 330and other window systems.
328 331
@@ -349,7 +352,7 @@ people who read it.
349 A @dfn{meta character} is a character typed with the @key{META} 352 A @dfn{meta character} is a character typed with the @key{META}
350modifier key. The integer that represents such a character has the 353modifier key. The integer that represents such a character has the
351@tex 354@tex
352$2^{27}$ 355@math{2^{27}}
353@end tex 356@end tex
354@ifinfo 357@ifinfo
3552**27 3582**27
@@ -360,14 +363,14 @@ of basic character codes.
360 363
361 In a string, the 364 In a string, the
362@tex 365@tex
363$2^{7}$ 366@math{2^{7}}
364@end tex 367@end tex
365@ifinfo 368@ifinfo
3662**7 3692**7
367@end ifinfo 370@end ifinfo
368bit attached to an ASCII character indicates a meta character; thus, the 371bit attached to an ASCII character indicates a meta character; thus, the
369meta characters that can fit in a string have codes in the range from 372meta characters that can fit in a string have codes in the range from
370128 to 255, and are the meta versions of the ordinary @sc{ASCII} 373128 to 255, and are the meta versions of the ordinary @sc{ascii}
371characters. (In Emacs versions 18 and older, this convention was used 374characters. (In Emacs versions 18 and older, this convention was used
372for characters outside of strings as well.) 375for characters outside of strings as well.)
373 376
@@ -379,11 +382,11 @@ or as @samp{?\M-\101}. Likewise, you can write @kbd{C-M-b} as
379@samp{?\M-\C-b}, @samp{?\C-\M-b}, or @samp{?\M-\002}. 382@samp{?\M-\C-b}, @samp{?\C-\M-b}, or @samp{?\M-\002}.
380 383
381 The case of a graphic character is indicated by its character code; 384 The case of a graphic character is indicated by its character code;
382for example, @sc{ASCII} distinguishes between the characters @samp{a} 385for example, @sc{ascii} distinguishes between the characters @samp{a}
383and @samp{A}. But @sc{ASCII} has no way to represent whether a control 386and @samp{A}. But @sc{ascii} has no way to represent whether a control
384character is upper case or lower case. Emacs uses the 387character is upper case or lower case. Emacs uses the
385@tex 388@tex
386$2^{25}$ 389@math{2^{25}}
387@end tex 390@end tex
388@ifinfo 391@ifinfo
3892**25 3922**25
@@ -405,7 +408,7 @@ significant in these prefixes.) Thus, @samp{?\H-\M-\A-x} represents
405@kbd{Alt-Hyper-Meta-x}. 408@kbd{Alt-Hyper-Meta-x}.
406@tex 409@tex
407Numerically, the 410Numerically, the
408bit values are $2^{22}$ for alt, $2^{23}$ for super and $2^{24}$ for hyper. 411bit values are @math{2^{22}} for alt, @math{2^{23}} for super and @math{2^{24}} for hyper.
409@end tex 412@end tex
410@ifinfo 413@ifinfo
411Numerically, the 414Numerically, the
@@ -420,9 +423,9 @@ character code in either octal or hex. To use octal, write a question
420mark followed by a backslash and the octal character code (up to three 423mark followed by a backslash and the octal character code (up to three
421octal digits); thus, @samp{?\101} for the character @kbd{A}, 424octal digits); thus, @samp{?\101} for the character @kbd{A},
422@samp{?\001} for the character @kbd{C-a}, and @code{?\002} for the 425@samp{?\001} for the character @kbd{C-a}, and @code{?\002} for the
423character @kbd{C-b}. Although this syntax can represent any @sc{ASCII} 426character @kbd{C-b}. Although this syntax can represent any @sc{ascii}
424character, it is preferred only when the precise octal value is more 427character, it is preferred only when the precise octal value is more
425important than the @sc{ASCII} representation. 428important than the @sc{ascii} representation.
426 429
427@example 430@example
428@group 431@group
@@ -520,6 +523,11 @@ char-to-string ; @r{A symbol named @samp{char-to-string}.}
520@end group 523@end group
521@end example 524@end example
522 525
526@cindex @samp{#:} read syntax
527 Normally the Lisp reader interns all symbols (@pxref{Creating
528Symbols}). To prevent interning, you can write @samp{#:} before the
529name of the symbol.
530
523@node Sequence Type 531@node Sequence Type
524@subsection Sequence Types 532@subsection Sequence Types
525 533
@@ -559,7 +567,7 @@ same object, @code{nil}.
559 567
560 A @dfn{cons cell} is an object that consists of two slots, called the 568 A @dfn{cons cell} is an object that consists of two slots, called the
561@sc{car} slot and the @sc{cdr} slot. Each slot can @dfn{hold} or 569@sc{car} slot and the @sc{cdr} slot. Each slot can @dfn{hold} or
562@dfn{refer to} any Lisp object. We also say that the ``the @sc{car} of 570@dfn{refer to} any Lisp object. We also say that ``the @sc{car} of
563this cons cell is'' whatever object its @sc{car} slot currently holds, 571this cons cell is'' whatever object its @sc{car} slot currently holds,
564and likewise for the @sc{cdr}. 572and likewise for the @sc{cdr}.
565 573
@@ -794,7 +802,8 @@ sets the variable @code{alist-of-colors} to an alist of three elements. In the
794first element, @code{rose} is the key and @code{red} is the value. 802first element, @code{rose} is the key and @code{red} is the value.
795 803
796 @xref{Association Lists}, for a further explanation of alists and for 804 @xref{Association Lists}, for a further explanation of alists and for
797functions that work on alists. 805functions that work on alists. @xref{Hash Tables}, for another kind of
806lookup table, which is much faster for handling a large number of keys.
798 807
799@node Array Type 808@node Array Type
800@subsection Array Type 809@subsection Array Type
@@ -884,9 +893,9 @@ but the newline is ignored if escaped."
884@node Non-ASCII in Strings 893@node Non-ASCII in Strings
885@subsubsection Non-ASCII Characters in Strings 894@subsubsection Non-ASCII Characters in Strings
886 895
887 You can include a non-@sc{ASCII} international character in a string 896 You can include a non-@sc{ascii} international character in a string
888constant by writing it literally. There are two text representations 897constant by writing it literally. There are two text representations
889for non-@sc{ASCII} characters in Emacs strings (and in buffers): unibyte 898for non-@sc{ascii} characters in Emacs strings (and in buffers): unibyte
890and multibyte. If the string constant is read from a multibyte source, 899and multibyte. If the string constant is read from a multibyte source,
891such as a multibyte buffer or string, or a file that would be visited as 900such as a multibyte buffer or string, or a file that would be visited as
892multibyte, then the character is read as a multibyte character, and that 901multibyte, then the character is read as a multibyte character, and that
@@ -895,7 +904,7 @@ unibyte source, then the character is read as unibyte and that makes the
895string unibyte. 904string unibyte.
896 905
897 You can also represent a multibyte non-@sc{ASCII} character with its 906 You can also represent a multibyte non-@sc{ASCII} character with its
898character code, using a hex escape, @samp{\x@var{nnnnnnn}}, with as many 907character code: use a hex escape, @samp{\x@var{nnnnnnn}}, with as many
899digits as necessary. (Multibyte non-@sc{ASCII} character codes are all 908digits as necessary. (Multibyte non-@sc{ASCII} character codes are all
900greater than 256.) Any character which is not a valid hex digit 909greater than 256.) Any character which is not a valid hex digit
901terminates this construct. If the next character in the string could be 910terminates this construct. If the next character in the string could be
@@ -906,7 +915,7 @@ constant is just like backslash-newline; it does not contribute any
906character to the string, but it does terminate the preceding hex escape. 915character to the string, but it does terminate the preceding hex escape.
907 916
908 Using a multibyte hex escape forces the string to multibyte. You can 917 Using a multibyte hex escape forces the string to multibyte. You can
909represent a unibyte non-@sc{ASCII} character with its character code, 918represent a unibyte non-@sc{ascii} character with its character code,
910which must be in the range from 128 (0200 octal) to 255 (0377 octal). 919which must be in the range from 128 (0200 octal) to 255 (0377 octal).
911This forces a unibyte string. 920This forces a unibyte string.
912 921
@@ -925,16 +934,16 @@ description of the read syntax for characters.
925 934
926 However, not all of the characters you can write with backslash 935 However, not all of the characters you can write with backslash
927escape-sequences are valid in strings. The only control characters that 936escape-sequences are valid in strings. The only control characters that
928a string can hold are the @sc{ASCII} control characters. Strings do not 937a string can hold are the @sc{ascii} control characters. Strings do not
929distinguish case in @sc{ASCII} control characters. 938distinguish case in @sc{ascii} control characters.
930 939
931 Properly speaking, strings cannot hold meta characters; but when a 940 Properly speaking, strings cannot hold meta characters; but when a
932string is to be used as a key sequence, there is a special convention 941string is to be used as a key sequence, there is a special convention
933that provides a way to represent meta versions of @sc{ASCII} characters in a 942that provides a way to represent meta versions of @sc{ascii} characters in a
934string. If you use the @samp{\M-} syntax to indicate a meta character 943string. If you use the @samp{\M-} syntax to indicate a meta character
935in a string constant, this sets the 944in a string constant, this sets the
936@tex 945@tex
937$2^{7}$ 946@math{2^{7}}
938@end tex 947@end tex
939@ifinfo 948@ifinfo
9402**7 9492**7
@@ -1043,7 +1052,7 @@ Syntax tables (@pxref{Syntax Tables}).
1043 A @dfn{bool-vector} is a one-dimensional array of elements that 1052 A @dfn{bool-vector} is a one-dimensional array of elements that
1044must be @code{t} or @code{nil}. 1053must be @code{t} or @code{nil}.
1045 1054
1046 The printed representation of a Bool-vector is like a string, except 1055 The printed representation of a bool-vector is like a string, except
1047that it begins with @samp{#&} followed by the length. The string 1056that it begins with @samp{#&} followed by the length. The string
1048constant that follows actually specifies the contents of the bool-vector 1057constant that follows actually specifies the contents of the bool-vector
1049as a bitmap---each ``character'' in the string contains 8 bits, which 1058as a bitmap---each ``character'' in the string contains 8 bits, which
@@ -1063,6 +1072,19 @@ these extras really make no difference.
1063 @result{} t 1072 @result{} t
1064@end example 1073@end example
1065 1074
1075@node Hash Table Type
1076@subsection Hash Table Type
1077
1078 A hash table is a very fast kind of lookup table, somewhat like an
1079alist in that it maps keys to corresponding values, but much faster.
1080Hash tables are a new feature in Emacs 21; they have no read syntax, and
1081print using hash notation. @xref{Hash Tables}.
1082
1083@example
1084(make-hash-table)
1085 @result{} #<hash-table 'eql nil 0/65 0x83af980>
1086@end example
1087
1066@node Function Type 1088@node Function Type
1067@subsection Function Type 1089@subsection Function Type
1068 1090
@@ -1156,11 +1178,11 @@ opening @samp{[}.
1156@subsection Autoload Type 1178@subsection Autoload Type
1157 1179
1158 An @dfn{autoload object} is a list whose first element is the symbol 1180 An @dfn{autoload object} is a list whose first element is the symbol
1159@code{autoload}. It is stored as the function definition of a symbol as 1181@code{autoload}. It is stored as the function definition of a symbol,
1160a placeholder for the real definition; it says that the real definition 1182where it serves as a placeholder for the real definition. The autoload
1161is found in a file of Lisp code that should be loaded when necessary. 1183object says that the real definition is found in a file of Lisp code
1162The autoload object contains the name of the file, plus some other 1184that should be loaded when necessary. It contains the name of the file,
1163information about the real definition. 1185plus some other information about the real definition.
1164 1186
1165 After the file has been loaded, the symbol should have a new function 1187 After the file has been loaded, the symbol should have a new function
1166definition that is not an autoload object. The new definition is then 1188definition that is not an autoload object. The new definition is then
@@ -1207,9 +1229,9 @@ buffer need not be displayed in any window.
1207 The contents of a buffer are much like a string, but buffers are not 1229 The contents of a buffer are much like a string, but buffers are not
1208used like strings in Emacs Lisp, and the available operations are 1230used like strings in Emacs Lisp, and the available operations are
1209different. For example, you can insert text efficiently into an 1231different. For example, you can insert text efficiently into an
1210existing buffer, whereas ``inserting'' text into a string requires 1232existing buffer, altering the buffer's contents, whereas ``inserting''
1211concatenating substrings, and the result is an entirely new string 1233text into a string requires concatenating substrings, and the result is
1212object. 1234an entirely new string object.
1213 1235
1214 Each buffer has a designated position called @dfn{point} 1236 Each buffer has a designated position called @dfn{point}
1215(@pxref{Positions}). At any time, one buffer is the @dfn{current 1237(@pxref{Positions}). At any time, one buffer is the @dfn{current
@@ -1431,6 +1453,69 @@ positions.
1431 1453
1432 @xref{Overlays}, for how to create and use overlays. 1454 @xref{Overlays}, for how to create and use overlays.
1433 1455
1456@node Circular Objects
1457@section Read Syntax for Circular Objects
1458@cindex circular structure, read syntax
1459@cindex shared structure, read syntax
1460@cindex @samp{#@var{n}=} read syntax
1461@cindex @samp{#@var{n}#} read syntax
1462
1463 In Emacs 21, to represent shared or circular structure within a
1464complex of Lisp objects, you can use the reader constructs
1465@samp{#@var{n}=} and @samp{#@var{n}#}.
1466
1467 Use @code{#@var{n}=} before an object to label it for later reference;
1468subsequently, you can use @code{#@var{n}#} to refer the same object in
1469another place. Here, @var{n} is some integer. For example, here is how
1470to make a list in which the first element recurs as the third element:
1471
1472@example
1473(#1=(a) b #1#)
1474@end example
1475
1476@noindent
1477This differs from ordinary syntax such as this
1478
1479@example
1480((a) b (a))
1481@end example
1482
1483@noindent
1484which would result in a list whose first and third elements
1485look alike but are not the same Lisp object. This shows the difference:
1486
1487@example
1488(prog1 nil
1489 (setq x '(#1=(a) b #1#)))
1490(eq (nth 0 x) (nth 2 x))
1491 @result{} t
1492(setq x '((a) b (a)))
1493(eq (nth 0 x) (nth 2 x))
1494 @result{} nil
1495@end example
1496
1497 You can also use the same syntax to make a circular structure, which
1498appears as an ``element'' within itself. Here is an example:
1499
1500@example
1501#1=(a #1#)
1502@end example
1503
1504@noindent
1505This makes a list whose second element is the list itself.
1506Here's how you can see that it really works:
1507
1508@example
1509(prog1 nil
1510 (setq x '#1=(a #1#)))
1511(eq x (cadr x))
1512 @result{} t
1513@end example
1514
1515 The Lisp printer can produce this syntax to record circular and shared
1516structure in a Lisp object, if you bind the variable @code{print-circle}
1517to a non-@code{nil} value. @xref{Output Variables}.
1518
1434@node Type Predicates 1519@node Type Predicates
1435@section Type Predicates 1520@section Type Predicates
1436@cindex predicates 1521@cindex predicates
@@ -1764,7 +1849,7 @@ arguments to see if their elements are the same. So, if two objects are
1764Comparison of strings is case-sensitive, but does not take account of 1849Comparison of strings is case-sensitive, but does not take account of
1765text properties---it compares only the characters in the strings. 1850text properties---it compares only the characters in the strings.
1766A unibyte string never equals a multibyte string unless the 1851A unibyte string never equals a multibyte string unless the
1767contents are entirely @sc{ASCII} (@pxref{Text Representations}). 1852contents are entirely @sc{ascii} (@pxref{Text Representations}).
1768 1853
1769@example 1854@example
1770@group 1855@group