Lisp (programming language): Difference between revisions

Content deleted Content added
note on the drawing style
Tag: Reverted
Undid revision 1294559618 by Cobalt pen (talk) - that doesn't improve the article
Line 306:
Of the many data structures that can be built out of cons cells, one of the most basic is called a ''proper list''. A proper list is either the special {{Lisp2|nil}} (empty list) symbol, or a cons in which the {{Lisp2|car}} points to a datum (which may be another cons structure, such as a list), and the {{Lisp2|cdr}} points to another proper list.
 
If a given cons is taken to be the head of a linked list (which it normally is), then its car points to the first element of the list, and its cdr points to the rest of the list. For this reason, the {{Lisp2|car}} and {{Lisp2|cdr}} functions are also called {{Lisp2|first}} and {{Lisp2|rest}} when referring to conses which are part of a linked list (rather than, say, a tree). This explains the iconographic particularity of the cons-cell being depicted with the cdr reference continuing on the same level.
 
Thus, a Lisp list is not an atomic object, as an instance of a container class in C++ or Java would be. A list is nothing more than an aggregate of linked conses. A variable that refers to a given list is simply a pointer to the first cons in the list. Traversal of a list can be done by ''cdring down'' the list; that is, taking successive cdrs to visit each cons of the list; or by using any of several [[higher-order function]]s to map a function over a list.