GNU Info

Info Node: (elisp)Cons Cells

(elisp)Cons Cells


Next: Lists as Boxes Up: Lists
Enter node , (file) or (file)node

Lists and Cons Cells
====================

   Lists in Lisp are not a primitive data type; they are built up from
"cons cells".  A cons cell is a data object that represents an ordered
pair.  That is, it has two slots, and each slot "holds", or "refers
to", some Lisp object.  One slot is known as the CAR, and the other is
known as the CDR.  (These names are traditional; see Note: Cons Cell
Type.)  CDR is pronounced "could-er."

   We say that "the CAR of this cons cell is" whatever object its CAR
slot currently holds, and likewise for the CDR.

   A list is a series of cons cells "chained together," so that each
cell refers to the next one.  There is one cons cell for each element of
the list.  By convention, the CARs of the cons cells hold the elements
of the list, and the CDRs are used to chain the list: the CDR slot of
each cons cell refers to the following cons cell.  The CDR of the last
cons cell is `nil'.  This asymmetry between the CAR and the CDR is
entirely a matter of convention; at the level of cons cells, the CAR
and CDR slots have the same characteristics.

   Because most cons cells are used as part of lists, the phrase "list
structure" has come to mean any structure made out of cons cells.

   The symbol `nil' is considered a list as well as a symbol; it is the
list with no elements.  For convenience, the symbol `nil' is considered
to have `nil' as its CDR (and also as its CAR).

   The CDR of any nonempty list L is a list containing all the elements
of L except the first.


automatically generated by info2www version 1.2.2.9