Mercurial > emacs
comparison lispref/objects.texi @ 7118:08d61ef58d13
*** empty log message ***
| author | Richard M. Stallman <rms@gnu.org> |
|---|---|
| date | Tue, 26 Apr 1994 22:08:09 +0000 |
| parents | dcbbdafaf41e |
| children | cd57cd335fff |
comparison
equal
deleted
inserted
replaced
| 7117:f1b6a927a442 | 7118:08d61ef58d13 |
|---|---|
| 1 @c -*-texinfo-*- | 1 @c -*-texinfo-*- |
| 2 @c This is part of the GNU Emacs Lisp Reference Manual. | 2 @c This is part of the GNU Emacs Lisp Reference Manual. |
| 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 |
| 10 @cindex type | 10 @cindex type |
| 11 @cindex data type | 11 @cindex data type |
| 38 it as a number; Lisp knows it is a vector, not a number. | 38 it as a number; Lisp knows it is a vector, not a number. |
| 39 | 39 |
| 40 In most languages, the programmer must declare the data type of each | 40 In most languages, the programmer must declare the data type of each |
| 41 variable, and the type is known by the compiler but not represented in | 41 variable, and the type is known by the compiler but not represented in |
| 42 the data. Such type declarations do not exist in Emacs Lisp. A Lisp | 42 the data. Such type declarations do not exist in Emacs Lisp. A Lisp |
| 43 variable can have any type of value, and remembers the type of any value | 43 variable can have any type of value, and it remembers whatever value |
| 44 you store in it. | 44 you store in it, type and all. |
| 45 | 45 |
| 46 This chapter describes the purpose, printed representation, and read | 46 This chapter describes the purpose, printed representation, and read |
| 47 syntax of each of the standard types in GNU Emacs Lisp. Details on how | 47 syntax of each of the standard types in GNU Emacs Lisp. Details on how |
| 48 to use these types can be found in later chapters. | 48 to use these types can be found in later chapters. |
| 49 | 49 |
| 130 * Integer Type:: Numbers without fractional parts. | 130 * Integer Type:: Numbers without fractional parts. |
| 131 * Floating Point Type:: Numbers with fractional parts and with a large range. | 131 * Floating Point Type:: Numbers with fractional parts and with a large range. |
| 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. |
| 139 * Symbol Type:: A multi-use object that refers to a function, | 139 * Symbol Type:: A multi-use object that refers to a function, |
| 140 variable, property list, or itself. | 140 variable, property list, or itself. |
| 168 on most machines, but is 25 or 26 bits on some systems. It is important | 168 on most machines, but is 25 or 26 bits on some systems. It is important |
| 169 to note that the Emacs Lisp arithmetic functions do not check for | 169 to note that the Emacs Lisp arithmetic functions do not check for |
| 170 overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit | 170 overflow. Thus @code{(1+ 8388607)} is @minus{}8388608 on 24-bit |
| 171 implementations.@refill | 171 implementations.@refill |
| 172 | 172 |
| 173 The read syntax for numbers is a sequence of (base ten) digits with an | 173 The read syntax for integers is a sequence of (base ten) digits with an |
| 174 optional sign at the beginning and an optional period at the end. The | 174 optional sign at the beginning and an optional period at the end. The |
| 175 printed representation produced by the Lisp interpreter never has a | 175 printed representation produced by the Lisp interpreter never has a |
| 176 leading @samp{+} or a final @samp{.}. | 176 leading @samp{+} or a final @samp{.}. |
| 177 | 177 |
| 178 @example | 178 @example |
| 240 @example | 240 @example |
| 241 ?Q @result{} 81 ?q @result{} 113 | 241 ?Q @result{} 81 ?q @result{} 113 |
| 242 @end example | 242 @end example |
| 243 | 243 |
| 244 You can use the same syntax for punctuation characters, but it is | 244 You can use the same syntax for punctuation characters, but it is |
| 245 often a good idea to add a @samp{\} to prevent Lisp mode from getting | 245 often a good idea to add a @samp{\} so that the Emacs commands for |
| 246 confused. For example, @samp{?\ } is the way to write the space | 246 editing Lisp code don't get confused. For example, @samp{?\ } is the |
| 247 character. If the character is @samp{\}, you @emph{must} use a second | 247 way to write the space character. If the character is @samp{\}, you |
| 248 @samp{\} to quote it: @samp{?\\}. | 248 @emph{must} use a second @samp{\} to quote it: @samp{?\\}. |
| 249 | 249 |
| 250 @cindex whitespace | 250 @cindex whitespace |
| 251 @cindex bell character | 251 @cindex bell character |
| 252 @cindex @samp{\a} | 252 @cindex @samp{\a} |
| 253 @cindex backspace | 253 @cindex backspace |
| 334 (In Emacs versions 18 and older, this convention was used for characters | 334 (In Emacs versions 18 and older, this convention was used for characters |
| 335 outside of strings as well.) | 335 outside of strings as well.) |
| 336 | 336 |
| 337 The read syntax for meta characters uses @samp{\M-}. For example, | 337 The read syntax for meta characters uses @samp{\M-}. For example, |
| 338 @samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with | 338 @samp{?\M-A} stands for @kbd{M-A}. You can use @samp{\M-} together with |
| 339 octal codes, @samp{\C-}, or any other syntax for a character. Thus, you | 339 octal character codes (see below), with @samp{\C-}, or with any other |
| 340 can write @kbd{M-A} as @samp{?\M-A}, or as @samp{?\M-\101}. Likewise, | 340 syntax for a character. Thus, you can write @kbd{M-A} as @samp{?\M-A}, |
| 341 you can write @kbd{C-M-b} as @samp{?\M-\C-b}, @samp{?\C-\M-b}, or | 341 or as @samp{?\M-\101}. Likewise, you can write @kbd{C-M-b} as |
| 342 @samp{?\M-\002}. | 342 @samp{?\M-\C-b}, @samp{?\C-\M-b}, or @samp{?\M-\002}. |
| 343 | 343 |
| 344 The case of an ordinary letter is indicated by its character code as | 344 The case of an ordinary letter is indicated by its character code as |
| 345 part of @sc{ASCII}, but @sc{ASCII} has no way to represent whether a | 345 part of @sc{ASCII}, but @sc{ASCII} has no way to represent whether a |
| 346 control character is upper case or lower case. Emacs uses the 2**21 bit | 346 control character is upper case or lower case. Emacs uses the 2**21 bit |
| 347 to indicate that the shift key was used for typing a control character. | 347 to indicate that the shift key was used for typing a control character. |
| 386 Lisp code. Also add a backslash before whitespace characters such as | 386 Lisp code. Also add a backslash before whitespace characters such as |
| 387 space, tab, newline and formfeed. However, it is cleaner to use one of | 387 space, tab, newline and formfeed. However, it is cleaner to use one of |
| 388 the easily readable escape sequences, such as @samp{\t}, instead of an | 388 the easily readable escape sequences, such as @samp{\t}, instead of an |
| 389 actual whitespace character such as a tab. | 389 actual whitespace character such as a tab. |
| 390 | 390 |
| 391 @node Symbol Type | |
| 392 @subsection Symbol Type | |
| 393 | |
| 394 A @dfn{symbol} in GNU Emacs Lisp is an object with a name. The symbol | |
| 395 name serves as the printed representation of the symbol. In ordinary | |
| 396 use, the name is unique---no two symbols have the same name. | |
| 397 | |
| 398 A symbol can serve as a variable, as a function name, or to hold a | |
| 399 property list. Or it may serve only to be distinct from all other Lisp | |
| 400 objects, so that its presence in a data structure may be recognized | |
| 401 reliably. In a given context, usually only one of these uses is | |
| 402 intended. But you can use one symbol in all of these ways, | |
| 403 independently. | |
| 404 | |
| 405 @cindex @samp{\} in symbols | |
| 406 @cindex backslash in symbols | |
| 407 A symbol name can contain any characters whatever. Most symbol names | |
| 408 are written with letters, digits, and the punctuation characters | |
| 409 @samp{-+=*/}. Such names require no special punctuation; the characters | |
| 410 of the name suffice as long as the name does not look like a number. | |
| 411 (If it does, write a @samp{\} at the beginning of the name to force | |
| 412 interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are | |
| 413 less often used but also require no special punctuation. Any other | |
| 414 characters may be included in a symbol's name by escaping them with a | |
| 415 backslash. In contrast to its use in strings, however, a backslash in | |
| 416 the name of a symbol simply quotes the single character that follows the | |
| 417 backslash. For example, in a string, @samp{\t} represents a tab | |
| 418 character; in the name of a symbol, however, @samp{\t} merely quotes the | |
| 419 letter @kbd{t}. To have a symbol with a tab character in its name, you | |
| 420 must actually use a tab (preceded with a backslash). But it's rare to | |
| 421 do such a thing. | |
| 422 | |
| 423 @cindex CL note---case of letters | |
| 424 @quotation | |
| 425 @b{Common Lisp note:} in Common Lisp, lower case letters are always | |
| 426 ``folded'' to upper case, unless they are explicitly escaped. This is | |
| 427 in contrast to Emacs Lisp, in which upper case and lower case letters | |
| 428 are distinct. | |
| 429 @end quotation | |
| 430 | |
| 431 Here are several examples of symbol names. Note that the @samp{+} in | |
| 432 the fifth example is escaped to prevent it from being read as a number. | |
| 433 This is not necessary in the last example because the rest of the name | |
| 434 makes it invalid as a number. | |
| 435 | |
| 436 @example | |
| 437 @group | |
| 438 foo ; @r{A symbol named @samp{foo}.} | |
| 439 FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.} | |
| 440 char-to-string ; @r{A symbol named @samp{char-to-string}.} | |
| 441 @end group | |
| 442 @group | |
| 443 1+ ; @r{A symbol named @samp{1+}} | |
| 444 ; @r{(not @samp{+1}, which is an integer).} | |
| 445 @end group | |
| 446 @group | |
| 447 \+1 ; @r{A symbol named @samp{+1}} | |
| 448 ; @r{(not a very readable name).} | |
| 449 @end group | |
| 450 @group | |
| 451 \(*\ 1\ 2\) ; @r{A symbol named @samp{(* 1 2)} (a worse name).} | |
| 452 @c the @'s in this next line use up three characters, hence the | |
| 453 @c apparent misalignment of the comment. | |
| 454 +-*/_~!@@$%^&=:<>@{@} ; @r{A symbol named @samp{+-*/_~!@@$%^&=:<>@{@}}.} | |
| 455 ; @r{These characters need not be escaped.} | |
| 456 @end group | |
| 457 @end example | |
| 458 | |
| 391 @node Sequence Type | 459 @node Sequence Type |
| 392 @subsection Sequence Types | 460 @subsection Sequence Types |
| 393 | 461 |
| 394 A @dfn{sequence} is a Lisp object that represents an ordered set of | 462 A @dfn{sequence} is a Lisp object that represents an ordered set of |
| 395 elements. There are two kinds of sequence in Emacs Lisp, lists and | 463 elements. There are two kinds of sequence in Emacs Lisp, lists and |
| 397 considered a sequence. | 465 considered a sequence. |
| 398 | 466 |
| 399 Arrays are further subdivided into strings and vectors. Vectors can | 467 Arrays are further subdivided into strings and vectors. Vectors can |
| 400 hold elements of any type, but string elements must be characters in the | 468 hold elements of any type, but string elements must be characters in the |
| 401 range from 0 to 255. However, the characters in a string can have text | 469 range from 0 to 255. However, the characters in a string can have text |
| 402 properties; vectors do not support text properties even when their | 470 properties like characters in a buffer (@pxref{Text Properties}); |
| 403 elements happen to be characters. | 471 vectors do not support text properties even when their elements happen |
| 472 to be characters. | |
| 404 | 473 |
| 405 Lists, strings and vectors are different, but they have important | 474 Lists, strings and vectors are different, but they have important |
| 406 similarities. For example, all have a length @var{l}, and all have | 475 similarities. For example, all have a length @var{l}, and all have |
| 407 elements which can be indexed from zero to @var{l} minus one. Also, | 476 elements which can be indexed from zero to @var{l} minus one. Also, |
| 408 several functions, called sequence functions, accept any kind of | 477 several functions, called sequence functions, accept any kind of |
| 414 always created anew upon reading. If you read the read syntax for a | 483 always created anew upon reading. If you read the read syntax for a |
| 415 sequence twice, you get two sequences with equal contents. There is one | 484 sequence twice, you get two sequences with equal contents. There is one |
| 416 exception: the empty list @code{()} always stands for the same object, | 485 exception: the empty list @code{()} always stands for the same object, |
| 417 @code{nil}. | 486 @code{nil}. |
| 418 | 487 |
| 419 @node List Type | 488 @node Cons Cell Type |
| 420 @subsection List Type | 489 @subsection Cons Cell and List Types |
| 421 @cindex address field of register | 490 @cindex address field of register |
| 422 @cindex decrement field of register | 491 @cindex decrement field of register |
| 423 | 492 |
| 424 A @dfn{list} is a series of cons cells, linked together. A @dfn{cons | 493 A @dfn{cons cell} is an object comprising two pointers named the |
| 425 cell} is an object comprising two pointers named the @sc{car} and the | 494 @sc{car} and the @sc{cdr}. Each of them can point to any Lisp object. |
| 426 @sc{cdr}. Each of them can point to any Lisp object, but when the cons | 495 |
| 427 cell is part of a list, the @sc{cdr} points either to another cons cell | 496 A @dfn{list} is a series of cons cells, linked together so that the |
| 428 or to the empty list. @xref{Lists}, for functions that work on lists. | 497 @sc{cdr} of each cons cell points either to another cons cell or to the |
| 498 empty list. @xref{Lists}, for functions that work on lists. Because | |
| 499 most cons cells are used as part of lists, the phrase @dfn{list | |
| 500 structure} has come to refer to any structure made out of cons cells. | |
| 429 | 501 |
| 430 The names @sc{car} and @sc{cdr} have only historical meaning now. The | 502 The names @sc{car} and @sc{cdr} have only historical meaning now. The |
| 431 original Lisp implementation ran on an @w{IBM 704} computer which | 503 original Lisp implementation ran on an @w{IBM 704} computer which |
| 432 divided words into two parts, called the ``address'' part and the | 504 divided words into two parts, called the ``address'' part and the |
| 433 ``decrement''; @sc{car} was an instruction to extract the contents of | 505 ``decrement''; @sc{car} was an instruction to extract the contents of |
| 447 right parenthesis. | 519 right parenthesis. |
| 448 | 520 |
| 449 Upon reading, each object inside the parentheses becomes an element | 521 Upon reading, each object inside the parentheses becomes an element |
| 450 of the list. That is, a cons cell is made for each element. The | 522 of the list. That is, a cons cell is made for each element. The |
| 451 @sc{car} of the cons cell points to the element, and its @sc{cdr} points | 523 @sc{car} of the cons cell points to the element, and its @sc{cdr} points |
| 452 to the next cons cell which holds the next element in the list. The | 524 to the next cons cell of the list, which holds the next element in the |
| 453 @sc{cdr} of the last cons cell is set to point to @code{nil}. | 525 list. The @sc{cdr} of the last cons cell is set to point to @code{nil}. |
| 454 | 526 |
| 455 @cindex box diagrams, for lists | 527 @cindex box diagrams, for lists |
| 456 @cindex diagrams, boxed, for lists | 528 @cindex diagrams, boxed, for lists |
| 457 A list can be illustrated by a diagram in which the cons cells are | 529 A list can be illustrated by a diagram in which the cons cells are |
| 458 shown as pairs of boxes. (The Lisp reader cannot read such an | 530 shown as pairs of boxes. (The Lisp reader cannot read such an |
| 459 illustration; unlike the textual notation, which can be understood both | 531 illustration; unlike the textual notation, which can be understood by |
| 460 humans and computers, the box illustrations can only be understood by | 532 both humans and computers, the box illustrations can be understood only |
| 461 humans.) The following represents the three-element list @code{(rose | 533 by humans.) The following represents the three-element list @code{(rose |
| 462 violet buttercup)}: | 534 violet buttercup)}: |
| 463 | 535 |
| 464 @example | 536 @example |
| 465 @group | 537 @group |
| 466 ___ ___ ___ ___ ___ ___ | 538 ___ ___ ___ ___ ___ ___ |
| 640 @node Array Type | 712 @node Array Type |
| 641 @subsection Array Type | 713 @subsection Array Type |
| 642 | 714 |
| 643 An @dfn{array} is composed of an arbitrary number of slots for | 715 An @dfn{array} is composed of an arbitrary number of slots for |
| 644 referring to other Lisp objects, arranged in a contiguous block of | 716 referring to other Lisp objects, arranged in a contiguous block of |
| 645 memory. Accessing any element of an array takes a the same amount of | 717 memory. Accessing any element of an array takes the same amount of |
| 646 time. In contrast, accessing an element of a list requires time | 718 time. In contrast, accessing an element of a list requires time |
| 647 proportional to the position of the element in the list. (Elements at | 719 proportional to the position of the element in the list. (Elements at |
| 648 the end of a list take longer to access than elements at the beginning | 720 the end of a list take longer to access than elements at the beginning |
| 649 of a list.) | 721 of a list.) |
| 650 | 722 |
| 692 If you use the @samp{\M-} syntax to indicate a meta character in a | 764 If you use the @samp{\M-} syntax to indicate a meta character in a |
| 693 string constant, this sets the 2**7 bit of the character in the string. | 765 string constant, this sets the 2**7 bit of the character in the string. |
| 694 This is not the same representation that the meta modifier has in a | 766 This is not the same representation that the meta modifier has in a |
| 695 character on its own (not inside a string). @xref{Character Type}. | 767 character on its own (not inside a string). @xref{Character Type}. |
| 696 | 768 |
| 697 Strings cannot hold characters that have the hyper, super or alt | 769 Strings cannot hold characters that have the hyper, super, or alt |
| 698 modifiers; they can hold @sc{ASCII} control characters, but no others. | 770 modifiers; they can hold @sc{ASCII} control characters, but no others. |
| 699 They do not distinguish case in @sc{ASCII} control characters. | 771 They do not distinguish case in @sc{ASCII} control characters. |
| 700 | 772 |
| 701 In contrast with the C programming language, Emacs Lisp allows | 773 The printed representation of a string consists of a double-quote, the |
| 702 newlines in string literals. But an escaped newline---one that is | 774 characters it contains, and another double-quote. However, you must |
| 703 preceded by @samp{\}---does not become part of the string; i.e., the | 775 escape any backslash or double-quote characters in the string with a |
| 704 Lisp reader ignores an escaped newline in a string literal. | 776 backslash, like this: @code{"this \" is an embedded quote"}. |
| 777 | |
| 778 The newline character is not special in the read syntax for strings; | |
| 779 if you write a new line between the double-quotes, it becomes a | |
| 780 character in the string. But an escaped newline---one that is preceded | |
| 781 by @samp{\}---does not become part of the string; i.e., the Lisp reader | |
| 782 ignores an escaped newline while reading a string. | |
| 705 @cindex newline in strings | 783 @cindex newline in strings |
| 706 | 784 |
| 707 @example | 785 @example |
| 708 "It is useful to include newlines | 786 "It is useful to include newlines |
| 709 in documentation strings, | 787 in documentation strings, |
| 712 @result{} "It is useful to include newlines | 790 @result{} "It is useful to include newlines |
| 713 in documentation strings, | 791 in documentation strings, |
| 714 but the newline is ignored if escaped." | 792 but the newline is ignored if escaped." |
| 715 @end example | 793 @end example |
| 716 | 794 |
| 717 The printed representation of a string consists of a double-quote, the | |
| 718 characters it contains, and another double-quote. However, any | |
| 719 backslash or double-quote characters in the string are preceded with a | |
| 720 backslash like this: @code{"this \" is an embedded quote"}. | |
| 721 | |
| 722 A string can hold properties of the text it contains, in addition to | 795 A string can hold properties of the text it contains, in addition to |
| 723 the characters themselves. This enables programs that copy text between | 796 the characters themselves. This enables programs that copy text between |
| 724 strings and buffers to preserve the properties with no special effort. | 797 strings and buffers to preserve the properties with no special effort. |
| 725 @xref{Text Properties}. Strings with text properties have a special | 798 @xref{Text Properties}. Strings with text properties have a special |
| 726 read and print syntax: | 799 read and print syntax: |
| 762 @result{} [1 "two" (three)] | 835 @result{} [1 "two" (three)] |
| 763 @end example | 836 @end example |
| 764 | 837 |
| 765 @xref{Vectors}, for functions that work with vectors. | 838 @xref{Vectors}, for functions that work with vectors. |
| 766 | 839 |
| 767 @node Symbol Type | 840 @node Function Type |
| 768 @subsection Symbol Type | 841 @subsection Function Type |
| 769 | |
| 770 A @dfn{symbol} in GNU Emacs Lisp is an object with a name. The symbol | |
| 771 name serves as the printed representation of the symbol. In ordinary | |
| 772 use, the name is unique---no two symbols have the same name. | |
| 773 | |
| 774 A symbol can serve as a variable, as a function name, or to hold a | |
| 775 property list. Or it may serve only to be distinct from all other Lisp | |
| 776 objects, so that its presence in a data structure may be recognized | |
| 777 reliably. In a given context, usually only one of these uses is | |
| 778 intended. But you can use one symbol in all of these ways, | |
| 779 independently. | |
| 780 | |
| 781 @cindex @samp{\} in symbols | |
| 782 @cindex backslash in symbols | |
| 783 A symbol name can contain any characters whatever. Most symbol names | |
| 784 are written with letters, digits, and the punctuation characters | |
| 785 @samp{-+=*/}. Such names require no special punctuation; the characters | |
| 786 of the name suffice as long as the name does not look like a number. | |
| 787 (If it does, write a @samp{\} at the beginning of the name to force | |
| 788 interpretation as a symbol.) The characters @samp{_~!@@$%^&:<>@{@}} are | |
| 789 less often used but also require no special punctuation. Any other | |
| 790 characters may be included in a symbol's name by escaping them with a | |
| 791 backslash. In contrast to its use in strings, however, a backslash in | |
| 792 the name of a symbol quotes the single character that follows the | |
| 793 backslash, without conversion. For example, in a string, @samp{\t} | |
| 794 represents a tab character; in the name of a symbol, however, @samp{\t} | |
| 795 merely quotes the letter @kbd{t}. To have a symbol with a tab character | |
| 796 in its name, you must actually use a tab (preceded with a backslash). | |
| 797 But it's rare to do such a thing. | |
| 798 | |
| 799 @cindex CL note---case of letters | |
| 800 @quotation | |
| 801 @b{Common Lisp note:} in Common Lisp, lower case letters are always | |
| 802 ``folded'' to upper case, unless they are explicitly escaped. This is | |
| 803 in contrast to Emacs Lisp, in which upper case and lower case letters | |
| 804 are distinct. | |
| 805 @end quotation | |
| 806 | |
| 807 Here are several examples of symbol names. Note that the @samp{+} in | |
| 808 the fifth example is escaped to prevent it from being read as a number. | |
| 809 This is not necessary in the last example because the rest of the name | |
| 810 makes it invalid as a number. | |
| 811 | |
| 812 @example | |
| 813 @group | |
| 814 foo ; @r{A symbol named @samp{foo}.} | |
| 815 FOO ; @r{A symbol named @samp{FOO}, different from @samp{foo}.} | |
| 816 char-to-string ; @r{A symbol named @samp{char-to-string}.} | |
| 817 @end group | |
| 818 @group | |
| 819 1+ ; @r{A symbol named @samp{1+}} | |
| 820 ; @r{(not @samp{+1}, which is an integer).} | |
| 821 @end group | |
| 822 @group | |
| 823 \+1 ; @r{A symbol named @samp{+1}} | |
| 824 ; @r{(not a very readable name).} | |
| 825 @end group | |
| 826 @group | |
| 827 \(*\ 1\ 2\) ; @r{A symbol named @samp{(* 1 2)} (a worse name).} | |
| 828 @c the @'s in this next line use up three characters, hence the | |
| 829 @c apparent misalignment of the comment. | |
| 830 +-*/_~!@@$%^&=:<>@{@} ; @r{A symbol named @samp{+-*/_~!@@$%^&=:<>@{@}}.} | |
| 831 ; @r{These characters need not be escaped.} | |
| 832 @end group | |
| 833 @end example | |
| 834 | |
| 835 @node Lisp Function Type | |
| 836 @subsection Lisp Function Type | |
| 837 | 842 |
| 838 Just as functions in other programming languages are executable, | 843 Just as functions in other programming languages are executable, |
| 839 @dfn{Lisp function} objects are pieces of executable code. However, | 844 @dfn{Lisp function} objects are pieces of executable code. However, |
| 840 functions in Lisp are primarily Lisp objects, and only secondarily the | 845 functions in Lisp are primarily Lisp objects, and only secondarily the |
| 841 text which represents them. These Lisp objects are lambda expressions: | 846 text which represents them. These Lisp objects are lambda expressions: |
| 851 Most of the time, functions are called when their names are written in | 856 Most of the time, functions are called when their names are written in |
| 852 Lisp expressions in Lisp programs. However, you can construct or obtain | 857 Lisp expressions in Lisp programs. However, you can construct or obtain |
| 853 a function object at run time and then call it with the primitive | 858 a function object at run time and then call it with the primitive |
| 854 functions @code{funcall} and @code{apply}. @xref{Calling Functions}. | 859 functions @code{funcall} and @code{apply}. @xref{Calling Functions}. |
| 855 | 860 |
| 856 @node Lisp Macro Type | 861 @node Macro Type |
| 857 @subsection Lisp Macro Type | 862 @subsection Macro Type |
| 858 | 863 |
| 859 A @dfn{Lisp macro} is a user-defined construct that extends the Lisp | 864 A @dfn{Lisp macro} is a user-defined construct that extends the Lisp |
| 860 language. It is represented as an object much like a function, but with | 865 language. It is represented as an object much like a function, but with |
| 861 different parameter-passing semantics. A Lisp macro has the form of a | 866 different parameter-passing semantics. A Lisp macro has the form of a |
| 862 list whose first element is the symbol @code{macro} and whose @sc{cdr} | 867 list whose first element is the symbol @code{macro} and whose @sc{cdr} |
| 885 is that the primitive function may be called directly from C code. | 890 is that the primitive function may be called directly from C code. |
| 886 Calls to the redefined function from Lisp will use the new definition, | 891 Calls to the redefined function from Lisp will use the new definition, |
| 887 but calls from C code may still use the built-in definition. | 892 but calls from C code may still use the built-in definition. |
| 888 | 893 |
| 889 The term @dfn{function} refers to all Emacs functions, whether written | 894 The term @dfn{function} refers to all Emacs functions, whether written |
| 890 in Lisp or C. @xref{Lisp Function Type}, for information about the | 895 in Lisp or C. @xref{Function Type}, for information about the |
| 891 functions written in Lisp.@refill | 896 functions written in Lisp. |
| 892 | 897 |
| 893 Primitive functions have no read syntax and print in hash notation | 898 Primitive functions have no read syntax and print in hash notation |
| 894 with the name of the subroutine. | 899 with the name of the subroutine. |
| 895 | 900 |
| 896 @example | 901 @example |
| 975 object. | 980 object. |
| 976 | 981 |
| 977 Each buffer has a designated position called @dfn{point} | 982 Each buffer has a designated position called @dfn{point} |
| 978 (@pxref{Positions}). At any time, one buffer is the @dfn{current | 983 (@pxref{Positions}). At any time, one buffer is the @dfn{current |
| 979 buffer}. Most editing commands act on the contents of the current | 984 buffer}. Most editing commands act on the contents of the current |
| 980 buffer in the neighborhood of point. Many other functions manipulate or | 985 buffer in the neighborhood of point. Many of the standard Emacs |
| 981 test the characters in the current buffer; a whole chapter in this | 986 functions manipulate or test the characters in the current buffer; a |
| 982 manual is devoted to describing these functions (@pxref{Text}). | 987 whole chapter in this manual is devoted to describing these functions |
| 988 (@pxref{Text}). | |
| 983 | 989 |
| 984 Several other data structures are associated with each buffer: | 990 Several other data structures are associated with each buffer: |
| 985 | 991 |
| 986 @itemize @bullet | 992 @itemize @bullet |
| 987 @item | 993 @item |
| 993 @item | 999 @item |
| 994 a local variable binding list (@pxref{Buffer-Local Variables}). | 1000 a local variable binding list (@pxref{Buffer-Local Variables}). |
| 995 @end itemize | 1001 @end itemize |
| 996 | 1002 |
| 997 @noindent | 1003 @noindent |
| 998 The local keymap and variable list contain entries which individually | 1004 The local keymap and variable list contain entries that individually |
| 999 override global bindings or values. These are used to customize the | 1005 override global bindings or values. These are used to customize the |
| 1000 behavior of programs in different buffers, without actually changing the | 1006 behavior of programs in different buffers, without actually changing the |
| 1001 programs. | 1007 programs. |
| 1002 | 1008 |
| 1003 Buffers have no read syntax. They print in hash notation with the | 1009 Buffers have no read syntax. They print in hash notation with the |
| 1142 Area}). | 1148 Area}). |
| 1143 | 1149 |
| 1144 Streams have no special printed representation or read syntax, and | 1150 Streams have no special printed representation or read syntax, and |
| 1145 print as whatever primitive type they are. | 1151 print as whatever primitive type they are. |
| 1146 | 1152 |
| 1147 @xref{Streams}, for a description of various functions related to | 1153 @xref{Streams, Reading and Printing}, for a description of functions |
| 1148 streams, including various parsing and printing functions. | 1154 related to streams, including parsing and printing functions. |
| 1149 | 1155 |
| 1150 @node Keymap Type | 1156 @node Keymap Type |
| 1151 @subsection Keymap Type | 1157 @subsection Keymap Type |
| 1152 | 1158 |
| 1153 A @dfn{keymap} maps keys typed by the user to commands. This mapping | 1159 A @dfn{keymap} maps keys typed by the user to commands. This mapping |
| 1165 buffer. For example, in C mode (@pxref{Major Modes}), the @samp{+} | 1171 buffer. For example, in C mode (@pxref{Major Modes}), the @samp{+} |
| 1166 character is punctuation, but in Lisp mode it is a valid character in a | 1172 character is punctuation, but in Lisp mode it is a valid character in a |
| 1167 symbol. These modes specify different interpretations by changing the | 1173 symbol. These modes specify different interpretations by changing the |
| 1168 syntax table entry for @samp{+}, at index 43 in the syntax table. | 1174 syntax table entry for @samp{+}, at index 43 in the syntax table. |
| 1169 | 1175 |
| 1170 Syntax tables are only used for scanning text in buffers, not for | 1176 Syntax tables are used only for scanning text in buffers, not for |
| 1171 reading Lisp expressions. The table the Lisp interpreter uses to read | 1177 reading Lisp expressions. The table the Lisp interpreter uses to read |
| 1172 expressions is built into the Emacs source code and cannot be changed; | 1178 expressions is built into the Emacs source code and cannot be changed; |
| 1173 thus, to change the list delimiters to be @samp{@{} and @samp{@}} | 1179 thus, to change the list delimiters to be @samp{@{} and @samp{@}} |
| 1174 instead of @samp{(} and @samp{)} would be impossible. | 1180 instead of @samp{(} and @samp{)} would be impossible. |
| 1175 | 1181 |
| 1210 a type that the function can use. | 1216 a type that the function can use. |
| 1211 | 1217 |
| 1212 All built-in functions do check the types of their actual arguments | 1218 All built-in functions do check the types of their actual arguments |
| 1213 when appropriate, and signal a @code{wrong-type-argument} error if an | 1219 when appropriate, and signal a @code{wrong-type-argument} error if an |
| 1214 argument is of the wrong type. For example, here is what happens if you | 1220 argument is of the wrong type. For example, here is what happens if you |
| 1215 pass an argument to @code{+} which it cannot handle: | 1221 pass an argument to @code{+} that it cannot handle: |
| 1216 | 1222 |
| 1217 @example | 1223 @example |
| 1218 @group | 1224 @group |
| 1219 (+ 2 'a) | 1225 (+ 2 'a) |
| 1220 @error{} Wrong type argument: integer-or-marker-p, a | 1226 @error{} Wrong type argument: integer-or-marker-p, a |
| 1277 @xref{List-related Predicates, listp}. | 1283 @xref{List-related Predicates, listp}. |
| 1278 | 1284 |
| 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}. |
| 1287 | 1293 |
| 1288 @item numberp | 1294 @item numberp |
| 1332 @section Equality Predicates | 1338 @section Equality Predicates |
| 1333 @cindex equality | 1339 @cindex equality |
| 1334 | 1340 |
| 1335 Here we describe two functions that test for equality between any two | 1341 Here we describe two functions that test for equality between any two |
| 1336 objects. Other functions test equality between objects of specific | 1342 objects. Other functions test equality between objects of specific |
| 1337 types, e.g., strings. See the appropriate chapter describing the data | 1343 types, e.g., strings. For these predicates, see the appropriate chapter |
| 1338 type for these predicates. | 1344 describing the data type. |
| 1339 | 1345 |
| 1340 @defun eq object1 object2 | 1346 @defun eq object1 object2 |
| 1341 This function returns @code{t} if @var{object1} and @var{object2} are | 1347 This function returns @code{t} if @var{object1} and @var{object2} are |
| 1342 the same object, @code{nil} otherwise. The ``same object'' means that a | 1348 the same object, @code{nil} otherwise. The ``same object'' means that a |
| 1343 change in one will be reflected by the same change in the other. | 1349 change in one will be reflected by the same change in the other. |
