Of all the types mentioned above, the one type we have not spent much time on already, yet demands attention is the ``cons cell''.
Lisp stands for List Processing, yet we have remained strangely silent on the topic of Lists. I am sure this is some kind of a record for introductory texts on Lisp - to talk about lists so late.
But before we look at lists, we need to look at Cons cells first. A cons cell is a data object that represents an ordered pair. That is, it has two slots, and each slot ``holds'' some lisp object. The first slot is called the CAR of the cons cell, while the other is called the CDR (pronounced 'could-er') slot. The car and cdr slots can hold objects of different types. A cons cell can be constructed using the cons built-in function, as the following illustrates:
(setq a (cons 1 2)) (setq b (cons 10 "abcd"))
Two built-in functions car and cdr are available to access the car and cdr cells respectively.
A ``list'' represents a sequence of zero or more elements. Lists, however, are not a primitive data type; they are built up from cons cells. It does not matter how exactly it is implemented internally; but it helps to visualise a list as a cons cell whose cdr is either nil or another list. So, the following is a legit. way of creating a list:
(setq lis (cons 1 (cons 2 nil)))
This can get cumbersome when building large lists so there are short cuts, ofcourse, like:
(setq lis (list 1 2))
The two methods yield the same results, but the first one illustrates exactly how the list is built up, while the second one hides that detail in favour of brevity.
You must note that the written representation of a list in a Lisp program is as a sequence of symbols enclosed in brackets. You must also note that this is the precise syntax of a Lisp expression itself!! In otherwords, your Lisp program is itself written as a series of Lists. This is a really interesting property, and you should spend some time reflecting on this. Internalising this concept would help you a little in understanding the realy profundity behing the cliche ``In Lisp code is data''.