diff options
| author | Richard M. Stallman | 2005-02-14 10:14:29 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-02-14 10:14:29 +0000 |
| commit | 23e69ab14b523136d671c22da8ca8ba16bef89e9 (patch) | |
| tree | c151297e170ea0d409af427a4daec84847fe9c4d | |
| parent | 38bf67d3aeae8223a01160a9c7f7f2bae4527521 (diff) | |
| download | emacs-23e69ab14b523136d671c22da8ca8ba16bef89e9.tar.gz emacs-23e69ab14b523136d671c22da8ca8ba16bef89e9.zip | |
(List-related Predicates): Minor wording improvement.
(Lists as Boxes): Node deleted.
(Building Lists): Explain trivial cases of number-sequence.
| -rw-r--r-- | lispref/lists.texi | 104 |
1 files changed, 13 insertions, 91 deletions
diff --git a/lispref/lists.texi b/lispref/lists.texi index d30dcb0c270..1aafe2614c3 100644 --- a/lispref/lists.texi +++ b/lispref/lists.texi | |||
| @@ -86,100 +86,17 @@ cells. | |||
| 86 | The @sc{cdr} of any nonempty list @var{l} is a list containing all the | 86 | The @sc{cdr} of any nonempty list @var{l} is a list containing all the |
| 87 | elements of @var{l} except the first. | 87 | elements of @var{l} except the first. |
| 88 | 88 | ||
| 89 | @node Lists as Boxes | ||
| 90 | @comment node-name, next, previous, up | ||
| 91 | @section Lists as Linked Pairs of Boxes | ||
| 92 | @cindex box representation for lists | ||
| 93 | @cindex lists represented as boxes | ||
| 94 | @cindex cons cell as box | ||
| 95 | |||
| 96 | A cons cell can be illustrated as a pair of boxes. The first box | ||
| 97 | represents the @sc{car} and the second box represents the @sc{cdr}. | ||
| 98 | Here is an illustration of the two-element list, @code{(tulip lily)}, | ||
| 99 | made from two cons cells: | ||
| 100 | |||
| 101 | @example | ||
| 102 | @group | ||
| 103 | --------------- --------------- | ||
| 104 | | car | cdr | | car | cdr | | ||
| 105 | | tulip | o---------->| lily | nil | | ||
| 106 | | | | | | | | ||
| 107 | --------------- --------------- | ||
| 108 | @end group | ||
| 109 | @end example | ||
| 110 | |||
| 111 | Each pair of boxes represents a cons cell. Each box ``refers to'', | ||
| 112 | ``points to'' or ``holds'' a Lisp object. (These terms are | ||
| 113 | synonymous.) The first box, which describes the @sc{car} of the first | ||
| 114 | cons cell, contains the symbol @code{tulip}. The arrow from the | ||
| 115 | @sc{cdr} box of the first cons cell to the second cons cell indicates | ||
| 116 | that the @sc{cdr} of the first cons cell is the second cons cell. | ||
| 117 | |||
| 118 | The same list can be illustrated in a different sort of box notation | ||
| 119 | like this: | ||
| 120 | |||
| 121 | @example | ||
| 122 | @group | ||
| 123 | --- --- --- --- | ||
| 124 | | | |--> | | |--> nil | ||
| 125 | --- --- --- --- | ||
| 126 | | | | ||
| 127 | | | | ||
| 128 | --> tulip --> lily | ||
| 129 | @end group | ||
| 130 | @end example | ||
| 131 | |||
| 132 | Here is a more complex illustration, showing the three-element list, | ||
| 133 | @code{((pine needles) oak maple)}, the first element of which is a | ||
| 134 | two-element list: | ||
| 135 | |||
| 136 | @example | ||
| 137 | @group | ||
| 138 | --- --- --- --- --- --- | ||
| 139 | | | |--> | | |--> | | |--> nil | ||
| 140 | --- --- --- --- --- --- | ||
| 141 | | | | | ||
| 142 | | | | | ||
| 143 | | --> oak --> maple | ||
| 144 | | | ||
| 145 | | --- --- --- --- | ||
| 146 | --> | | |--> | | |--> nil | ||
| 147 | --- --- --- --- | ||
| 148 | | | | ||
| 149 | | | | ||
| 150 | --> pine --> needles | ||
| 151 | @end group | ||
| 152 | @end example | ||
| 153 | |||
| 154 | The same list represented in the first box notation looks like this: | ||
| 155 | |||
| 156 | @example | ||
| 157 | @group | ||
| 158 | -------------- -------------- -------------- | ||
| 159 | | car | cdr | | car | cdr | | car | cdr | | ||
| 160 | | o | o------->| oak | o------->| maple | nil | | ||
| 161 | | | | | | | | | | | | ||
| 162 | -- | --------- -------------- -------------- | ||
| 163 | | | ||
| 164 | | | ||
| 165 | | -------------- ---------------- | ||
| 166 | | | car | cdr | | car | cdr | | ||
| 167 | ------>| pine | o------->| needles | nil | | ||
| 168 | | | | | | | | ||
| 169 | -------------- ---------------- | ||
| 170 | @end group | ||
| 171 | @end example | ||
| 172 | |||
| 173 | @xref{Cons Cell Type}, for the read and print syntax of cons cells and | 89 | @xref{Cons Cell Type}, for the read and print syntax of cons cells and |
| 174 | lists, and for more ``box and arrow'' illustrations of lists. | 90 | lists, and for more ``box and arrow'' illustrations of lists. |
| 175 | 91 | ||
| 176 | @node List-related Predicates | 92 | @node List-related Predicates |
| 177 | @section Predicates on Lists | 93 | @section Predicates on Lists |
| 178 | 94 | ||
| 179 | The following predicates test whether a Lisp object is an atom, is a | 95 | The following predicates test whether a Lisp object is an atom, |
| 180 | cons cell or is a list, or whether it is the distinguished object | 96 | whether it is a cons cell or is a list, or whether it is the |
| 181 | @code{nil}. (Many of these predicates can be defined in terms of the | 97 | distinguished object @code{nil}. (Many of these predicates can be |
| 182 | others, but they are used so often that it is worth having all of them.) | 98 | defined in terms of the others, but they are used so often that it is |
| 99 | worth having all of them.) | ||
| 183 | 100 | ||
| 184 | @defun consp object | 101 | @defun consp object |
| 185 | This function returns @code{t} if @var{object} is a cons cell, @code{nil} | 102 | This function returns @code{t} if @var{object} is a cons cell, @code{nil} |
| @@ -749,9 +666,14 @@ This returns a list of numbers starting with @var{from} and | |||
| 749 | incrementing by @var{separation}, and ending at or just before | 666 | incrementing by @var{separation}, and ending at or just before |
| 750 | @var{to}. @var{separation} can be positive or negative and defaults | 667 | @var{to}. @var{separation} can be positive or negative and defaults |
| 751 | to 1. If @var{to} is @code{nil} or numerically equal to @var{from}, | 668 | to 1. If @var{to} is @code{nil} or numerically equal to @var{from}, |
| 752 | the one element list @code{(from)} is returned. If @var{separation} | 669 | the value is the one-element list @code{(@var{from})}. If @var{to} is |
| 753 | is 0 and @var{to} is neither @code{nil} nor numerically equal to | 670 | less than @var{from} with a positive @var{separation}, or greater than |
| 754 | @var{from}, an error is signaled. | 671 | @var{from} with a negative @var{separation}, the value is @code{nil} |
| 672 | because those arguments specify an empty sequence. | ||
| 673 | |||
| 674 | If @var{separation} is 0 and @var{to} is neither @code{nil} nor | ||
| 675 | numerically equal to @var{from}, @code{number-sequence} signals an | ||
| 676 | error, since those arguments specify an infinite sequence. | ||
| 755 | 677 | ||
| 756 | All arguments can be integers or floating point numbers. However, | 678 | All arguments can be integers or floating point numbers. However, |
| 757 | floating point arguments can be tricky, because floating point | 679 | floating point arguments can be tricky, because floating point |