86 |
The @sc{cdr} of any nonempty list @var{l} is a list containing all the |
The @sc{cdr} of any nonempty list @var{l} is a list containing all the |
87 |
elements of @var{l} except the first. |
elements of @var{l} except the first. |
88 |
|
|
|
@node Lists as Boxes |
|
|
@comment node-name, next, previous, up |
|
|
@section Lists as Linked Pairs of Boxes |
|
|
@cindex box representation for lists |
|
|
@cindex lists represented as boxes |
|
|
@cindex cons cell as box |
|
|
|
|
|
A cons cell can be illustrated as a pair of boxes. The first box |
|
|
represents the @sc{car} and the second box represents the @sc{cdr}. |
|
|
Here is an illustration of the two-element list, @code{(tulip lily)}, |
|
|
made from two cons cells: |
|
|
|
|
|
@example |
|
|
@group |
|
|
--------------- --------------- |
|
|
| car | cdr | | car | cdr | |
|
|
| tulip | o---------->| lily | nil | |
|
|
| | | | | | |
|
|
--------------- --------------- |
|
|
@end group |
|
|
@end example |
|
|
|
|
|
Each pair of boxes represents a cons cell. Each box ``refers to'', |
|
|
``points to'' or ``holds'' a Lisp object. (These terms are |
|
|
synonymous.) The first box, which describes the @sc{car} of the first |
|
|
cons cell, contains the symbol @code{tulip}. The arrow from the |
|
|
@sc{cdr} box of the first cons cell to the second cons cell indicates |
|
|
that the @sc{cdr} of the first cons cell is the second cons cell. |
|
|
|
|
|
The same list can be illustrated in a different sort of box notation |
|
|
like this: |
|
|
|
|
|
@example |
|
|
@group |
|
|
--- --- --- --- |
|
|
| | |--> | | |--> nil |
|
|
--- --- --- --- |
|
|
| | |
|
|
| | |
|
|
--> tulip --> lily |
|
|
@end group |
|
|
@end example |
|
|
|
|
|
Here is a more complex illustration, showing the three-element list, |
|
|
@code{((pine needles) oak maple)}, the first element of which is a |
|
|
two-element list: |
|
|
|
|
|
@example |
|
|
@group |
|
|
--- --- --- --- --- --- |
|
|
| | |--> | | |--> | | |--> nil |
|
|
--- --- --- --- --- --- |
|
|
| | | |
|
|
| | | |
|
|
| --> oak --> maple |
|
|
| |
|
|
| --- --- --- --- |
|
|
--> | | |--> | | |--> nil |
|
|
--- --- --- --- |
|
|
| | |
|
|
| | |
|
|
--> pine --> needles |
|
|
@end group |
|
|
@end example |
|
|
|
|
|
The same list represented in the first box notation looks like this: |
|
|
|
|
|
@example |
|
|
@group |
|
|
-------------- -------------- -------------- |
|
|
| car | cdr | | car | cdr | | car | cdr | |
|
|
| o | o------->| oak | o------->| maple | nil | |
|
|
| | | | | | | | | | |
|
|
-- | --------- -------------- -------------- |
|
|
| |
|
|
| |
|
|
| -------------- ---------------- |
|
|
| | car | cdr | | car | cdr | |
|
|
------>| pine | o------->| needles | nil | |
|
|
| | | | | | |
|
|
-------------- ---------------- |
|
|
@end group |
|
|
@end example |
|
|
|
|
89 |
@xref{Cons Cell Type}, for the read and print syntax of cons cells and |
@xref{Cons Cell Type}, for the read and print syntax of cons cells and |
90 |
lists, and for more ``box and arrow'' illustrations of lists. |
lists, and for more ``box and arrow'' illustrations of lists. |
91 |
|
|
92 |
@node List-related Predicates |
@node List-related Predicates |
93 |
@section Predicates on Lists |
@section Predicates on Lists |
94 |
|
|
95 |
The following predicates test whether a Lisp object is an atom, is a |
The following predicates test whether a Lisp object is an atom, |
96 |
cons cell or is a list, or whether it is the distinguished object |
whether it is a cons cell or is a list, or whether it is the |
97 |
@code{nil}. (Many of these predicates can be defined in terms of the |
distinguished object @code{nil}. (Many of these predicates can be |
98 |
others, but they are used so often that it is worth having all of them.) |
defined in terms of the others, but they are used so often that it is |
99 |
|
worth having all of them.) |
100 |
|
|
101 |
@defun consp object |
@defun consp object |
102 |
This function returns @code{t} if @var{object} is a cons cell, @code{nil} |
This function returns @code{t} if @var{object} is a cons cell, @code{nil} |
666 |
incrementing by @var{separation}, and ending at or just before |
incrementing by @var{separation}, and ending at or just before |
667 |
@var{to}. @var{separation} can be positive or negative and defaults |
@var{to}. @var{separation} can be positive or negative and defaults |
668 |
to 1. If @var{to} is @code{nil} or numerically equal to @var{from}, |
to 1. If @var{to} is @code{nil} or numerically equal to @var{from}, |
669 |
the one element list @code{(from)} is returned. If @var{separation} |
the value is the one-element list @code{(@var{from})}. If @var{to} is |
670 |
is 0 and @var{to} is neither @code{nil} nor numerically equal to |
less than @var{from} with a positive @var{separation}, or greater than |
671 |
@var{from}, an error is signaled. |
@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. |
677 |
|
|
678 |
All arguments can be integers or floating point numbers. However, |
All arguments can be integers or floating point numbers. However, |
679 |
floating point arguments can be tricky, because floating point |
floating point arguments can be tricky, because floating point |