aboutsummaryrefslogtreecommitdiffstats
path: root/lispref/objects.texi
diff options
context:
space:
mode:
authorRichard M. Stallman1998-05-27 23:47:15 +0000
committerRichard M. Stallman1998-05-27 23:47:15 +0000
commitebc6903b2989b2de3154afd59fece90ba3882306 (patch)
treeda680e9d8aae919f6e876338d629d8b718ca24f8 /lispref/objects.texi
parent40f406674acfc16eb1f01fd23de83a0329e65eea (diff)
downloademacs-ebc6903b2989b2de3154afd59fece90ba3882306.tar.gz
emacs-ebc6903b2989b2de3154afd59fece90ba3882306.zip
*** empty log message ***
Diffstat (limited to 'lispref/objects.texi')
-rw-r--r--lispref/objects.texi99
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
322bit as well as the code for the corresponding non-control 322bit as well as the code for the corresponding non-control
323character. Ordinary terminals have no way of generating non-@sc{ASCII} 323character. Ordinary terminals have no way of generating non-@sc{ASCII}
324control characters, but you can generate them straightforwardly using an 324control characters, but you can generate them straightforwardly using X
325X terminal. 325and 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
328the control equivalent of @kbd{?}: 328the control equivalent of @kbd{?}:
@@ -433,7 +433,7 @@ important than the @sc{ASCII} representation.
433and the hexadecimal character code. You can use any number of hex 433and the hexadecimal character code. You can use any number of hex
434digits, so you can represent any character code in this way. 434digits, so you can represent any character code in this way.
435Thus, @samp{?\x41} for the character @kbd{A}, @samp{?\x1} for the 435Thus, @samp{?\x41} for the character @kbd{A}, @samp{?\x1} for the
436character @kbd{C-a}, and @code{?\x8c0} for the character 436character @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. 559called 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
562currently 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
562empty list. @xref{Lists}, for functions that work on lists. Because 566empty list. @xref{Lists}, for functions that work on lists. Because
563most cons cells are used as part of lists, the phrase @dfn{list 567most cons cells are used as part of lists, the phrase @dfn{list
564structure} has come to refer to any structure made out of cons cells. 568structure} 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
567original Lisp implementation ran on an @w{IBM 704} computer which 571original Lisp implementation ran on an @w{IBM 704} computer which
568divided words into two parts, called the ``address'' part and the 572divided 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
586of the list. That is, a cons cell is made for each element. The 590of 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}
588to the next cons cell of the list, which holds the next element in the 592slot points to the next cons cell of the list, which holds the next
589list. The @sc{cdr} of the last cons cell is set to point to @code{nil}. 593element in the list. The @sc{cdr} slot of the last cons cell is set to
594point 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
594shown as pairs of boxes. (The Lisp reader cannot read such an 599shown as pairs of boxes, like dominoes. (The Lisp reader cannot read
595illustration; unlike the textual notation, which can be understood by 600such an illustration; unlike the textual notation, which can be
596both humans and computers, the box illustrations can be understood only 601understood by both humans and computers, the box illustrations can be
597by humans.) The following represents the three-element list @code{(rose 602understood only by humans.) This picture represents the three-element
598violet buttercup)}: 603list @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
612object. Each pair of boxes represents a cons cell. Each arrow is a 617object. Each pair of boxes represents a cons cell. Each arrow is a
613reference to a Lisp object, either an atom or another cons cell. 618pointer 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
616refers to or ``contains'' @code{rose} (a symbol). The second box, the 621cons 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 622box, holding the @sc{cdr} of the first cons cell, points to the next
618second cons cell. The @sc{car} of the second cons cell refers to 623pair 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 624cell 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
622Here is another diagram of the same list, @code{(rose violet 627 Here is another diagram of the same list, @code{(rose violet
623buttercup)}, sketched in a different manner: 628buttercup)}, 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,
683the object @var{a}, and whose @sc{cdr} is the object @var{b}. Dotted 688the object @var{a}, and whose @sc{cdr} is the object @var{b}. Dotted
684pair notation is therefore more general than list syntax. In the dotted 689pair notation is therefore more general than list syntax. In the dotted
685pair notation, the list @samp{(1 2 3)} is written as @samp{(1 . (2 . (3 690pair 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
687the same result, but list notation is usually clearer and more 692notation, but list notation is usually clearer and more convenient.
688convenient when it is applicable. When printing a list, the dotted pair 693When printing a list, the dotted pair notation is only used if the
689notation 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.
692shows the pair @code{(rose . violet)}: 697This 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
706chain of cons cells with a non-@code{nil} final @sc{cdr}. For example, 711conveniently a chain of cons cells with a non-@code{nil} final @sc{cdr}.
707@code{(rose violet . buttercup)} is equivalent to @code{(rose . (violet 712You 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))}.
715The 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
722buttercup)}} is invalid syntax; it would require a cons cell that has 729there is nothing that it could mean. If anything, it would say to put
723three parts rather than two. 730@code{buttercup} in the @sc{cdr} of a cons cell whose @sc{cdr} is already
731used 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))},
726and looks like this: 734and 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
786referring to other Lisp objects, arranged in a contiguous block of 794pointing to other Lisp objects, arranged in a contiguous block of
787memory. Accessing any element of an array takes approximately the same 795memory. Accessing any element of an array takes approximately the same
788amount of time. In contrast, accessing an element of a list requires 796amount of time. In contrast, accessing an element of a list requires
789time proportional to the position of the element in the list. (Elements 797time 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
883digits as necessary. (Multibyte non-@sc{ASCII} character codes are all 891digits as necessary. (Multibyte non-@sc{ASCII} character codes are all
884greater than 256.) Any character which is not a valid hex digit 892greater than 256.) Any character which is not a valid hex digit
885terminates this construct. If the character that would follow is a hex 893terminates this construct. If the character that would follow is a hex
886digit, write @w{@samp{\ }} to terminate the hex escape---for example, 894digit, write @w{@samp{\ }} (backslash and space)
887@w{@samp{\x8c0\ }} represents one character, @samp{a} with grave accent. 895to 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
889not contribute any character to the string, but it does terminate the 898not contribute any character to the string, but it does terminate the
890preceding hex escape. 899preceding 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
916string is to be used as a key sequence, there is a special convention 925string is to be used as a key sequence, there is a special convention
917that allows the meta versions of @sc{ASCII} characters to be put in a 926that provides a way to represent meta versions of @sc{ASCII} characters in a
918string. If you use the @samp{\M-} syntax to indicate a meta character 927string. If you use the @samp{\M-} syntax to indicate a meta character
919in a string constant, this sets the 928in a string constant, this sets the
920@tex 929@tex
@@ -965,7 +974,7 @@ that range. For example,
965represents a string whose textual contents are @samp{foo bar}, in which 974represents a string whose textual contents are @samp{foo bar}, in which
966the first three characters have a @code{face} property with value 975the 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
969property list is @code{nil}. It is not actually necessary to mention 978property list is @code{nil}. It is not actually necessary to mention
970ranges with @code{nil} as the property list, since any characters not 979ranges with @code{nil} as the property list, since any characters not
971mentioned in any range will default to having no properties.) 980mentioned in any range will default to having no properties.)
@@ -1032,8 +1041,8 @@ that it begins with @samp{#&} followed by the length. The string
1032constant that follows actually specifies the contents of the bool-vector 1041constant that follows actually specifies the contents of the bool-vector
1033as a bitmap---each ``character'' in the string contains 8 bits, which 1042as a bitmap---each ``character'' in the string contains 8 bits, which
1034specify the next 8 elements of the bool-vector (1 stands for @code{t}, 1043specify the next 8 elements of the bool-vector (1 stands for @code{t},
1035and 0 for @code{nil}). The least significant bits of the character are 1044and 0 for @code{nil}). The least significant bits of the character
1036the lowest-numbered elements of the bool-vector. If the length is not a 1045correspond to the lowest indices in the bool-vector. If the length is not a
1037multiple of 8, the printed representation shows extra elements, but 1046multiple of 8, the printed representation shows extra elements, but
1038these extras really make no difference. 1047these extras really make no difference.
1039 1048