diff options
| author | Richard M. Stallman | 1998-05-27 23:47:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-27 23:47:15 +0000 |
| commit | ebc6903b2989b2de3154afd59fece90ba3882306 (patch) | |
| tree | da680e9d8aae919f6e876338d629d8b718ca24f8 /lispref/objects.texi | |
| parent | 40f406674acfc16eb1f01fd23de83a0329e65eea (diff) | |
| download | emacs-ebc6903b2989b2de3154afd59fece90ba3882306.tar.gz emacs-ebc6903b2989b2de3154afd59fece90ba3882306.zip | |
*** empty log message ***
Diffstat (limited to 'lispref/objects.texi')
| -rw-r--r-- | lispref/objects.texi | 99 |
1 files changed, 54 insertions, 45 deletions
diff --git a/lispref/objects.texi b/lispref/objects.texi index f2c082b56bc..ccdc1756fe3 100644 --- a/lispref/objects.texi +++ b/lispref/objects.texi | |||
| @@ -321,8 +321,8 @@ $2^{26}$ | |||
| 321 | @end ifinfo | 321 | @end ifinfo |
| 322 | bit as well as the code for the corresponding non-control | 322 | bit as well as the code for the corresponding non-control |
| 323 | character. Ordinary terminals have no way of generating non-@sc{ASCII} | 323 | character. Ordinary terminals have no way of generating non-@sc{ASCII} |
| 324 | control characters, but you can generate them straightforwardly using an | 324 | control characters, but you can generate them straightforwardly using X |
| 325 | X terminal. | 325 | and other window systems. |
| 326 | 326 | ||
| 327 | For historical reasons, Emacs treats the @key{DEL} character as | 327 | For historical reasons, Emacs treats the @key{DEL} character as |
| 328 | the control equivalent of @kbd{?}: | 328 | the control equivalent of @kbd{?}: |
| @@ -433,7 +433,7 @@ important than the @sc{ASCII} representation. | |||
| 433 | and the hexadecimal character code. You can use any number of hex | 433 | and the hexadecimal character code. You can use any number of hex |
| 434 | digits, so you can represent any character code in this way. | 434 | digits, so you can represent any character code in this way. |
| 435 | Thus, @samp{?\x41} for the character @kbd{A}, @samp{?\x1} for the | 435 | Thus, @samp{?\x41} for the character @kbd{A}, @samp{?\x1} for the |
| 436 | character @kbd{C-a}, and @code{?\x8c0} for the character | 436 | character @kbd{C-a}, and @code{?\x8e0} for the character |
| 437 | @iftex | 437 | @iftex |
| 438 | @samp{@`a}. | 438 | @samp{@`a}. |
| 439 | @end iftex | 439 | @end iftex |
| @@ -553,17 +553,21 @@ same object, @code{nil}. | |||
| 553 | @subsection Cons Cell and List Types | 553 | @subsection Cons Cell and List Types |
| 554 | @cindex address field of register | 554 | @cindex address field of register |
| 555 | @cindex decrement field of register | 555 | @cindex decrement field of register |
| 556 | @cindex pointers | ||
| 556 | 557 | ||
| 557 | A @dfn{cons cell} is an object comprising two pointers named the | 558 | A @dfn{cons cell} is an object that consists of two pointers or slots, |
| 558 | @sc{car} and the @sc{cdr}. Each of them can point to any Lisp object. | 559 | called the @sc{car} slot and the @sc{cdr} slot. Each slot can |
| 560 | @dfn{point to} or hold to any Lisp object. We also say that the ``the | ||
| 561 | @sc{car} of this cons cell is'' whatever object its @sc{car} slot | ||
| 562 | currently points to, and likewise for the @sc{cdr}. | ||
| 559 | 563 | ||
| 560 | A @dfn{list} is a series of cons cells, linked together so that the | 564 | A @dfn{list} is a series of cons cells, linked together so that the |
| 561 | @sc{cdr} of each cons cell points either to another cons cell or to the | 565 | @sc{cdr} slot of each cons cell holds either the next cons cell or the |
| 562 | empty list. @xref{Lists}, for functions that work on lists. Because | 566 | empty list. @xref{Lists}, for functions that work on lists. Because |
| 563 | most cons cells are used as part of lists, the phrase @dfn{list | 567 | most cons cells are used as part of lists, the phrase @dfn{list |
| 564 | structure} has come to refer to any structure made out of cons cells. | 568 | structure} has come to refer to any structure made out of cons cells. |
| 565 | 569 | ||
| 566 | The names @sc{car} and @sc{cdr} have only historical meaning now. The | 570 | The names @sc{car} and @sc{cdr} derive from the history of Lisp. The |
| 567 | original Lisp implementation ran on an @w{IBM 704} computer which | 571 | original Lisp implementation ran on an @w{IBM 704} computer which |
| 568 | divided words into two parts, called the ``address'' part and the | 572 | divided words into two parts, called the ``address'' part and the |
| 569 | ``decrement''; @sc{car} was an instruction to extract the contents of | 573 | ``decrement''; @sc{car} was an instruction to extract the contents of |
| @@ -584,18 +588,19 @@ right parenthesis. | |||
| 584 | 588 | ||
| 585 | Upon reading, each object inside the parentheses becomes an element | 589 | Upon reading, each object inside the parentheses becomes an element |
| 586 | of the list. That is, a cons cell is made for each element. The | 590 | of the list. That is, a cons cell is made for each element. The |
| 587 | @sc{car} of the cons cell points to the element, and its @sc{cdr} points | 591 | @sc{car} slot of the cons cell points to the element, and its @sc{cdr} |
| 588 | to the next cons cell of the list, which holds the next element in the | 592 | slot points to the next cons cell of the list, which holds the next |
| 589 | list. The @sc{cdr} of the last cons cell is set to point to @code{nil}. | 593 | element in the list. The @sc{cdr} slot of the last cons cell is set to |
| 594 | point to @code{nil}. | ||
| 590 | 595 | ||
| 591 | @cindex box diagrams, for lists | 596 | @cindex box diagrams, for lists |
| 592 | @cindex diagrams, boxed, for lists | 597 | @cindex diagrams, boxed, for lists |
| 593 | A list can be illustrated by a diagram in which the cons cells are | 598 | A list can be illustrated by a diagram in which the cons cells are |
| 594 | shown as pairs of boxes. (The Lisp reader cannot read such an | 599 | shown as pairs of boxes, like dominoes. (The Lisp reader cannot read |
| 595 | illustration; unlike the textual notation, which can be understood by | 600 | such an illustration; unlike the textual notation, which can be |
| 596 | both humans and computers, the box illustrations can be understood only | 601 | understood by both humans and computers, the box illustrations can be |
| 597 | by humans.) The following represents the three-element list @code{(rose | 602 | understood only by humans.) This picture represents the three-element |
| 598 | violet buttercup)}: | 603 | list @code{(rose violet buttercup)}: |
| 599 | 604 | ||
| 600 | @example | 605 | @example |
| 601 | @group | 606 | @group |
| @@ -608,18 +613,18 @@ violet buttercup)}: | |||
| 608 | @end group | 613 | @end group |
| 609 | @end example | 614 | @end example |
| 610 | 615 | ||
| 611 | In this diagram, each box represents a slot that can refer to any Lisp | 616 | In this diagram, each box represents a slot that can point to any Lisp |
| 612 | object. Each pair of boxes represents a cons cell. Each arrow is a | 617 | object. Each pair of boxes represents a cons cell. Each arrow is a |
| 613 | reference to a Lisp object, either an atom or another cons cell. | 618 | pointer to a Lisp object, either an atom or another cons cell. |
| 614 | 619 | ||
| 615 | In this example, the first box, the @sc{car} of the first cons cell, | 620 | In this example, the first box, which holds the @sc{car} of the first |
| 616 | refers to or ``contains'' @code{rose} (a symbol). The second box, the | 621 | cons cell, points to or ``contains'' @code{rose} (a symbol). The second |
| 617 | @sc{cdr} of the first cons cell, refers to the next pair of boxes, the | 622 | box, holding the @sc{cdr} of the first cons cell, points to the next |
| 618 | second cons cell. The @sc{car} of the second cons cell refers to | 623 | pair of boxes, the second cons cell. The @sc{car} of the second cons |
| 619 | @code{violet} and the @sc{cdr} refers to the third cons cell. The | 624 | cell is @code{violet}, and its @sc{cdr} is the third cons cell. The |
| 620 | @sc{cdr} of the third (and last) cons cell refers to @code{nil}. | 625 | @sc{cdr} of the third (and last) cons cell is @code{nil}. |
| 621 | 626 | ||
| 622 | Here is another diagram of the same list, @code{(rose violet | 627 | Here is another diagram of the same list, @code{(rose violet |
| 623 | buttercup)}, sketched in a different manner: | 628 | buttercup)}, sketched in a different manner: |
| 624 | 629 | ||
| 625 | @smallexample | 630 | @smallexample |
| @@ -683,13 +688,13 @@ that represents the @sc{car} and @sc{cdr} explicitly. In this syntax, | |||
| 683 | the object @var{a}, and whose @sc{cdr} is the object @var{b}. Dotted | 688 | the object @var{a}, and whose @sc{cdr} is the object @var{b}. Dotted |
| 684 | pair notation is therefore more general than list syntax. In the dotted | 689 | pair notation is therefore more general than list syntax. In the dotted |
| 685 | pair notation, the list @samp{(1 2 3)} is written as @samp{(1 . (2 . (3 | 690 | pair notation, the list @samp{(1 2 3)} is written as @samp{(1 . (2 . (3 |
| 686 | . nil)))}. For @code{nil}-terminated lists, the two notations produce | 691 | . nil)))}. For @code{nil}-terminated lists, you can use either |
| 687 | the same result, but list notation is usually clearer and more | 692 | notation, but list notation is usually clearer and more convenient. |
| 688 | convenient when it is applicable. When printing a list, the dotted pair | 693 | When printing a list, the dotted pair notation is only used if the |
| 689 | notation is only used if the @sc{cdr} of a cell is not a list. | 694 | @sc{cdr} of a cons cell is not a list. |
| 690 | 695 | ||
| 691 | Here's how box notation can illustrate dotted pairs. This example | 696 | Here's an example using boxes to illustrate dotted pair notation. |
| 692 | shows the pair @code{(rose . violet)}: | 697 | This example shows the pair @code{(rose . violet)}: |
| 693 | 698 | ||
| 694 | @example | 699 | @example |
| 695 | @group | 700 | @group |
| @@ -702,10 +707,12 @@ shows the pair @code{(rose . violet)}: | |||
| 702 | @end group | 707 | @end group |
| 703 | @end example | 708 | @end example |
| 704 | 709 | ||
| 705 | Dotted pair notation can be combined with list notation to represent a | 710 | You can combine dotted pair notation with list notation to represent |
| 706 | chain of cons cells with a non-@code{nil} final @sc{cdr}. For example, | 711 | conveniently a chain of cons cells with a non-@code{nil} final @sc{cdr}. |
| 707 | @code{(rose violet . buttercup)} is equivalent to @code{(rose . (violet | 712 | You write a dot after the last element of the list, followed by the |
| 708 | . buttercup))}. The object looks like this: | 713 | @sc{cdr} of the final cons cell. For example, @code{(rose violet |
| 714 | . buttercup)} is equivalent to @code{(rose . (violet . buttercup))}. | ||
| 715 | The object looks like this: | ||
| 709 | 716 | ||
| 710 | @example | 717 | @example |
| 711 | @group | 718 | @group |
| @@ -718,11 +725,12 @@ chain of cons cells with a non-@code{nil} final @sc{cdr}. For example, | |||
| 718 | @end group | 725 | @end group |
| 719 | @end example | 726 | @end example |
| 720 | 727 | ||
| 721 | These diagrams make it evident why @w{@code{(rose .@: violet .@: | 728 | The syntax @code{(rose .@: violet .@: buttercup)} is invalid because |
| 722 | buttercup)}} is invalid syntax; it would require a cons cell that has | 729 | there is nothing that it could mean. If anything, it would say to put |
| 723 | three parts rather than two. | 730 | @code{buttercup} in the @sc{cdr} of a cons cell whose @sc{cdr} is already |
| 731 | used for @code{violet}. | ||
| 724 | 732 | ||
| 725 | The list @code{(rose violet)} is equivalent to @code{(rose . (violet))} | 733 | The list @code{(rose violet)} is equivalent to @code{(rose . (violet))}, |
| 726 | and looks like this: | 734 | and looks like this: |
| 727 | 735 | ||
| 728 | @example | 736 | @example |
| @@ -783,7 +791,7 @@ functions that work on alists. | |||
| 783 | @subsection Array Type | 791 | @subsection Array Type |
| 784 | 792 | ||
| 785 | An @dfn{array} is composed of an arbitrary number of slots for | 793 | An @dfn{array} is composed of an arbitrary number of slots for |
| 786 | referring to other Lisp objects, arranged in a contiguous block of | 794 | pointing to other Lisp objects, arranged in a contiguous block of |
| 787 | memory. Accessing any element of an array takes approximately the same | 795 | memory. Accessing any element of an array takes approximately the same |
| 788 | amount of time. In contrast, accessing an element of a list requires | 796 | amount of time. In contrast, accessing an element of a list requires |
| 789 | time proportional to the position of the element in the list. (Elements | 797 | time proportional to the position of the element in the list. (Elements |
| @@ -883,8 +891,9 @@ character code, using a hex escape, @samp{\x@var{nnnnnnn}}, with as many | |||
| 883 | digits as necessary. (Multibyte non-@sc{ASCII} character codes are all | 891 | digits as necessary. (Multibyte non-@sc{ASCII} character codes are all |
| 884 | greater than 256.) Any character which is not a valid hex digit | 892 | greater than 256.) Any character which is not a valid hex digit |
| 885 | terminates this construct. If the character that would follow is a hex | 893 | terminates this construct. If the character that would follow is a hex |
| 886 | digit, write @w{@samp{\ }} to terminate the hex escape---for example, | 894 | digit, write @w{@samp{\ }} (backslash and space) |
| 887 | @w{@samp{\x8c0\ }} represents one character, @samp{a} with grave accent. | 895 | to terminate the hex escape---for example, |
| 896 | @w{@samp{\x8e0\ }} represents one character, @samp{a} with grave accent. | ||
| 888 | @w{@samp{\ }} in a string constant is just like backslash-newline; it does | 897 | @w{@samp{\ }} in a string constant is just like backslash-newline; it does |
| 889 | not contribute any character to the string, but it does terminate the | 898 | not contribute any character to the string, but it does terminate the |
| 890 | preceding hex escape. | 899 | preceding hex escape. |
| @@ -914,7 +923,7 @@ distinguish case in @sc{ASCII} control characters. | |||
| 914 | 923 | ||
| 915 | Properly speaking, strings cannot hold meta characters; but when a | 924 | Properly speaking, strings cannot hold meta characters; but when a |
| 916 | string is to be used as a key sequence, there is a special convention | 925 | string is to be used as a key sequence, there is a special convention |
| 917 | that allows the meta versions of @sc{ASCII} characters to be put in a | 926 | that provides a way to represent meta versions of @sc{ASCII} characters in a |
| 918 | string. If you use the @samp{\M-} syntax to indicate a meta character | 927 | string. If you use the @samp{\M-} syntax to indicate a meta character |
| 919 | in a string constant, this sets the | 928 | in a string constant, this sets the |
| 920 | @tex | 929 | @tex |
| @@ -965,7 +974,7 @@ that range. For example, | |||
| 965 | represents a string whose textual contents are @samp{foo bar}, in which | 974 | represents a string whose textual contents are @samp{foo bar}, in which |
| 966 | the first three characters have a @code{face} property with value | 975 | the first three characters have a @code{face} property with value |
| 967 | @code{bold}, and the last three have a @code{face} property with value | 976 | @code{bold}, and the last three have a @code{face} property with value |
| 968 | @code{italic}. (The fourth character has no text properties so its | 977 | @code{italic}. (The fourth character has no text properties, so its |
| 969 | property list is @code{nil}. It is not actually necessary to mention | 978 | property list is @code{nil}. It is not actually necessary to mention |
| 970 | ranges with @code{nil} as the property list, since any characters not | 979 | ranges with @code{nil} as the property list, since any characters not |
| 971 | mentioned in any range will default to having no properties.) | 980 | mentioned in any range will default to having no properties.) |
| @@ -1032,8 +1041,8 @@ that it begins with @samp{#&} followed by the length. The string | |||
| 1032 | constant that follows actually specifies the contents of the bool-vector | 1041 | constant that follows actually specifies the contents of the bool-vector |
| 1033 | as a bitmap---each ``character'' in the string contains 8 bits, which | 1042 | as a bitmap---each ``character'' in the string contains 8 bits, which |
| 1034 | specify the next 8 elements of the bool-vector (1 stands for @code{t}, | 1043 | specify the next 8 elements of the bool-vector (1 stands for @code{t}, |
| 1035 | and 0 for @code{nil}). The least significant bits of the character are | 1044 | and 0 for @code{nil}). The least significant bits of the character |
| 1036 | the lowest-numbered elements of the bool-vector. If the length is not a | 1045 | correspond to the lowest indices in the bool-vector. If the length is not a |
| 1037 | multiple of 8, the printed representation shows extra elements, but | 1046 | multiple of 8, the printed representation shows extra elements, but |
| 1038 | these extras really make no difference. | 1047 | these extras really make no difference. |
| 1039 | 1048 | ||