Chapter 5. Lists and pairs

Table of Contents
Print representation
Side-effects vs. functional programming

Pairs and the empty list are the building blocks of programs that make heavy use of Lisp list-processing style. Pairs are composed to create lists.

The terminology used here and in R4RS are slightly different, in that we consider a list to be anything that is either a pair or an empty list. A proper list, on the other hand, is a list that is acyclic in the cdrs and for which every cdr itself a proper list. In contrast, R4RS defines a list to be what we call a proper list.

Print representation

The print representation of a pair involves enclosing the contents in parentheses with a dot, or period, seperating the car and cdr. This print representation is referred to as a dotted pair.

Since lists are common and involve repeated occurrences of pairs in cdr positions, a special case print representation is available to these kinds of pairs. In this case, the as long as the cdr of a pair is also a list, the dot and recursive set of parentheses are elided. Furthermore, if the cdr is the empty list, then nothing is printed instead of ". ()". Hence, a proper list is represented merely as the contents of the list within parentheses.

(list 1 2 3) (1 2 3)