Node: Lists, Next: , Previous: Sequences, Up: Top


In Lpp, as with Lisp, lists are built up using cons cells and a list is defined as either a cons or nil. In Lpp a cons cell is an Lpp object with just two members. The car is thought of as the left member and the cdr as the right member. Ordinary lists are built up with conses, where for each cons its car contains the contents of the list element and its cdr contains a pointer to another cons cell. Such a list is usually terminated with nil in the cdr of the last cons cell of the list. Lists are printed with the Lpp printing functions exactly as they are in Common Lisp. For example the list of the three symbols a b c is printed as

             (a b c)

A list with a non-nil in the last cdr is called a dotted list. A one element list with a non-nil in the cdr is called a dotted pair. Note that a one element list is a single cons cell. Dotted pairs are useful in association lists or anywhere an efficient container for associated dynamic typed variables is needed. They are called dotted pairs because they are printed in Lisp and by the Lpp printing functions as

             (x . y)

where x is the car and y is the cdr. A dotted list would be printed like

             (a b c . d)

A list can also be circular. For example in the dotted list above if instead of d in the cdr of the last cons it contained the list itself then it would be circular. A list that is not circular or dotted is called a proper list.

As can be seen from the flexibility of cons cells as dotted pairs and lists, cons cells are also useful for building trees. For the purpose of this manual a tree is any Lpp object that may be an atom (a non-cons object) or a cons whose car and/or cdr may contain another cons nested to any level. Lists can also be used as sets with various set operations.