diff options
| author | Richard M. Stallman | 1999-09-17 06:59:04 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1999-09-17 06:59:04 +0000 |
| commit | 8241495da57ca0efed1b2e86ff693b5614e0aebd (patch) | |
| tree | ee1fca7ca3eafe24dbbf651622196bc849203e69 /lispref/objects.texi | |
| parent | 106217c6600b3049f1c62afaf198b9382206acba (diff) | |
| download | emacs-8241495da57ca0efed1b2e86ff693b5614e0aebd.tar.gz emacs-8241495da57ca0efed1b2e86ff693b5614e0aebd.zip | |
*** empty log message ***
Diffstat (limited to 'lispref/objects.texi')
| -rw-r--r-- | lispref/objects.texi | 161 |
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. | |||
| 25 | which all other types are constructed, are called @dfn{primitive | 25 | which all other types are constructed, are called @dfn{primitive |
| 26 | types}. Each object belongs to one and only one primitive type. These | 26 | types}. Each object belongs to one and only one primitive type. These |
| 27 | types include @dfn{integer}, @dfn{float}, @dfn{cons}, @dfn{symbol}, | 27 | types 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 |
| 29 | several special types, such as @dfn{buffer}, that are related to | 29 | several special types, such as @dfn{buffer}, that are related to |
| 30 | editing. (@xref{Editing Types}.) | 30 | editing. (@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 |
| 169 | to | 171 | to |
| 170 | @ifinfo | 172 | @ifinfo |
| 171 | 2**27 - 1) | 173 | 2**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 |
| 176 | on most machines. (Some machines may provide a wider range.) It is | 178 | on most machines. (Some machines may provide a wider range.) It is |
| 177 | important to note that the Emacs Lisp arithmetic functions do not check | 179 | important 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.} |
| 189 | 1 ; @r{The integer 1.} | 191 | 1 ; @r{The integer 1.} |
| 190 | 1. ; @r{Also The integer 1.} | 192 | 1. ; @r{Also the integer 1.} |
| 191 | +1 ; @r{Also the integer 1.} | 193 | +1 ; @r{Also the integer 1.} |
| 192 | 268435457 ; @r{Also the integer 1 on a 28-bit implementation.} | 194 | 268435457 ; @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 |
| 218 | other words, characters are represented by their character codes. For | 220 | other 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 |
| 315 | that exist in @sc{ASCII}; but for keyboard input purposes, you can turn | 318 | that exist in @sc{ascii}; but for keyboard input purposes, you can turn |
| 316 | any character into a control character with @samp{C-}. The character | 319 | any character into a control character with @samp{C-}. The character |
| 317 | codes for these non-@sc{ASCII} control characters include the | 320 | codes 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 |
| 322 | 2**26 | 325 | 2**26 |
| 323 | @end ifinfo | 326 | @end ifinfo |
| 324 | bit as well as the code for the corresponding non-control | 327 | bit as well as the code for the corresponding non-control |
| 325 | character. Ordinary terminals have no way of generating non-@sc{ASCII} | 328 | character. Ordinary terminals have no way of generating non-@sc{ascii} |
| 326 | control characters, but you can generate them straightforwardly using X | 329 | control characters, but you can generate them straightforwardly using X |
| 327 | and other window systems. | 330 | and 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} |
| 350 | modifier key. The integer that represents such a character has the | 353 | modifier 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 |
| 355 | 2**27 | 358 | 2**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 |
| 366 | 2**7 | 369 | 2**7 |
| 367 | @end ifinfo | 370 | @end ifinfo |
| 368 | bit attached to an ASCII character indicates a meta character; thus, the | 371 | bit attached to an ASCII character indicates a meta character; thus, the |
| 369 | meta characters that can fit in a string have codes in the range from | 372 | meta characters that can fit in a string have codes in the range from |
| 370 | 128 to 255, and are the meta versions of the ordinary @sc{ASCII} | 373 | 128 to 255, and are the meta versions of the ordinary @sc{ascii} |
| 371 | characters. (In Emacs versions 18 and older, this convention was used | 374 | characters. (In Emacs versions 18 and older, this convention was used |
| 372 | for characters outside of strings as well.) | 375 | for 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; |
| 382 | for example, @sc{ASCII} distinguishes between the characters @samp{a} | 385 | for example, @sc{ascii} distinguishes between the characters @samp{a} |
| 383 | and @samp{A}. But @sc{ASCII} has no way to represent whether a control | 386 | and @samp{A}. But @sc{ascii} has no way to represent whether a control |
| 384 | character is upper case or lower case. Emacs uses the | 387 | character 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 |
| 389 | 2**25 | 392 | 2**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 |
| 407 | Numerically, the | 410 | Numerically, the |
| 408 | bit values are $2^{22}$ for alt, $2^{23}$ for super and $2^{24}$ for hyper. | 411 | bit 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 |
| 411 | Numerically, the | 414 | Numerically, the |
| @@ -420,9 +423,9 @@ character code in either octal or hex. To use octal, write a question | |||
| 420 | mark followed by a backslash and the octal character code (up to three | 423 | mark followed by a backslash and the octal character code (up to three |
| 421 | octal digits); thus, @samp{?\101} for the character @kbd{A}, | 424 | octal 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 |
| 423 | character @kbd{C-b}. Although this syntax can represent any @sc{ASCII} | 426 | character @kbd{C-b}. Although this syntax can represent any @sc{ascii} |
| 424 | character, it is preferred only when the precise octal value is more | 427 | character, it is preferred only when the precise octal value is more |
| 425 | important than the @sc{ASCII} representation. | 428 | important 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 | ||
| 528 | Symbols}). To prevent interning, you can write @samp{#:} before the | ||
| 529 | name 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 |
| 563 | this cons cell is'' whatever object its @sc{car} slot currently holds, | 571 | this cons cell is'' whatever object its @sc{car} slot currently holds, |
| 564 | and likewise for the @sc{cdr}. | 572 | and 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 | |||
| 794 | first element, @code{rose} is the key and @code{red} is the value. | 802 | first 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 |
| 797 | functions that work on alists. | 805 | functions that work on alists. @xref{Hash Tables}, for another kind of |
| 806 | lookup 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 |
| 888 | constant by writing it literally. There are two text representations | 897 | constant by writing it literally. There are two text representations |
| 889 | for non-@sc{ASCII} characters in Emacs strings (and in buffers): unibyte | 898 | for non-@sc{ascii} characters in Emacs strings (and in buffers): unibyte |
| 890 | and multibyte. If the string constant is read from a multibyte source, | 899 | and multibyte. If the string constant is read from a multibyte source, |
| 891 | such as a multibyte buffer or string, or a file that would be visited as | 900 | such as a multibyte buffer or string, or a file that would be visited as |
| 892 | multibyte, then the character is read as a multibyte character, and that | 901 | multibyte, 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 | |||
| 895 | string unibyte. | 904 | string 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 |
| 898 | character code, using a hex escape, @samp{\x@var{nnnnnnn}}, with as many | 907 | character code: use a hex escape, @samp{\x@var{nnnnnnn}}, with as many |
| 899 | digits as necessary. (Multibyte non-@sc{ASCII} character codes are all | 908 | digits as necessary. (Multibyte non-@sc{ASCII} character codes are all |
| 900 | greater than 256.) Any character which is not a valid hex digit | 909 | greater than 256.) Any character which is not a valid hex digit |
| 901 | terminates this construct. If the next character in the string could be | 910 | terminates 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 | |||
| 906 | character to the string, but it does terminate the preceding hex escape. | 915 | character 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 |
| 909 | represent a unibyte non-@sc{ASCII} character with its character code, | 918 | represent a unibyte non-@sc{ascii} character with its character code, |
| 910 | which must be in the range from 128 (0200 octal) to 255 (0377 octal). | 919 | which must be in the range from 128 (0200 octal) to 255 (0377 octal). |
| 911 | This forces a unibyte string. | 920 | This 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 |
| 927 | escape-sequences are valid in strings. The only control characters that | 936 | escape-sequences are valid in strings. The only control characters that |
| 928 | a string can hold are the @sc{ASCII} control characters. Strings do not | 937 | a string can hold are the @sc{ascii} control characters. Strings do not |
| 929 | distinguish case in @sc{ASCII} control characters. | 938 | distinguish 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 |
| 932 | string is to be used as a key sequence, there is a special convention | 941 | string is to be used as a key sequence, there is a special convention |
| 933 | that provides a way to represent meta versions of @sc{ASCII} characters in a | 942 | that provides a way to represent meta versions of @sc{ascii} characters in a |
| 934 | string. If you use the @samp{\M-} syntax to indicate a meta character | 943 | string. If you use the @samp{\M-} syntax to indicate a meta character |
| 935 | in a string constant, this sets the | 944 | in 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 |
| 940 | 2**7 | 949 | 2**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 |
| 1044 | must be @code{t} or @code{nil}. | 1053 | must 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 |
| 1047 | that it begins with @samp{#&} followed by the length. The string | 1056 | that it begins with @samp{#&} followed by the length. The string |
| 1048 | constant that follows actually specifies the contents of the bool-vector | 1057 | constant that follows actually specifies the contents of the bool-vector |
| 1049 | as a bitmap---each ``character'' in the string contains 8 bits, which | 1058 | as 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 | ||
| 1079 | alist in that it maps keys to corresponding values, but much faster. | ||
| 1080 | Hash tables are a new feature in Emacs 21; they have no read syntax, and | ||
| 1081 | print 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, |
| 1160 | a placeholder for the real definition; it says that the real definition | 1182 | where it serves as a placeholder for the real definition. The autoload |
| 1161 | is found in a file of Lisp code that should be loaded when necessary. | 1183 | object says that the real definition is found in a file of Lisp code |
| 1162 | The autoload object contains the name of the file, plus some other | 1184 | that should be loaded when necessary. It contains the name of the file, |
| 1163 | information about the real definition. | 1185 | plus 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 |
| 1166 | definition that is not an autoload object. The new definition is then | 1188 | definition 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 |
| 1208 | used like strings in Emacs Lisp, and the available operations are | 1230 | used like strings in Emacs Lisp, and the available operations are |
| 1209 | different. For example, you can insert text efficiently into an | 1231 | different. For example, you can insert text efficiently into an |
| 1210 | existing buffer, whereas ``inserting'' text into a string requires | 1232 | existing buffer, altering the buffer's contents, whereas ``inserting'' |
| 1211 | concatenating substrings, and the result is an entirely new string | 1233 | text into a string requires concatenating substrings, and the result is |
| 1212 | object. | 1234 | an 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 | ||
| 1464 | complex 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; | ||
| 1468 | subsequently, you can use @code{#@var{n}#} to refer the same object in | ||
| 1469 | another place. Here, @var{n} is some integer. For example, here is how | ||
| 1470 | to 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 | ||
| 1477 | This differs from ordinary syntax such as this | ||
| 1478 | |||
| 1479 | @example | ||
| 1480 | ((a) b (a)) | ||
| 1481 | @end example | ||
| 1482 | |||
| 1483 | @noindent | ||
| 1484 | which would result in a list whose first and third elements | ||
| 1485 | look 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 | ||
| 1498 | appears as an ``element'' within itself. Here is an example: | ||
| 1499 | |||
| 1500 | @example | ||
| 1501 | #1=(a #1#) | ||
| 1502 | @end example | ||
| 1503 | |||
| 1504 | @noindent | ||
| 1505 | This makes a list whose second element is the list itself. | ||
| 1506 | Here'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 | ||
| 1516 | structure in a Lisp object, if you bind the variable @code{print-circle} | ||
| 1517 | to 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 | |||
| 1764 | Comparison of strings is case-sensitive, but does not take account of | 1849 | Comparison of strings is case-sensitive, but does not take account of |
| 1765 | text properties---it compares only the characters in the strings. | 1850 | text properties---it compares only the characters in the strings. |
| 1766 | A unibyte string never equals a multibyte string unless the | 1851 | A unibyte string never equals a multibyte string unless the |
| 1767 | contents are entirely @sc{ASCII} (@pxref{Text Representations}). | 1852 | contents are entirely @sc{ascii} (@pxref{Text Representations}). |
| 1768 | 1853 | ||
| 1769 | @example | 1854 | @example |
| 1770 | @group | 1855 | @group |