Believe it or not, this is actually a religious question.
There are dialects that people dare to refer to as some kind of Lisp in which empty lists are conses or aggregate objects of some kind, rather than just an atom like nil
.
For example, in "MatzLisp" (better known as Ruby) lists are actually arrays.
In NewLisp, lists are containers: objects of list type which contain a linked list of the items, so empty lists are empty containers. [Reference].
In Lisp languages that aren't spectacular cluster-fumbles of this sort, empty lists are atoms, and non-empty lists are binary cells with a field which holds the first item, and another field that holds the rest of the list. Lists can share suffixes. Given a list like (1 2 3)
we can use cons
to create (a 1 2 3)
and (b c 1 2 3)
both of which share the storage for (1 2 3)
.
(In ANSI Common Lisp, the empty list atom ()
is the same object as the symbol nil
, which evaluates to itself and also serves as Boolean false. In Scheme, ()
isn't a symbol, and is distinct from the Boolean false #f
object. However Scheme lists are still made up of pairs, and terminated by an atom.)
The ability to evaluate (car nil)
does not automatically follow from the cons-and-nil representation of lists, and if we look at ancient Lisp documentation, such as the Lisp 1.5 manual from early 1960-something, we will find that this was absent. Initially, car
was strictly a way to access a field of the cons cell, and required strictly a cons cell argument.
Good ideas like allowing (car nil)
to Just Work (so that hackers could trim many useless lines of code from their programs) didn't appear overnight. The idea of allowing (car nil)
may have appeared from InterLisp. In any case, Evolution Of Lisp paper claims that MacLisp (one of the important predecessors of Common Lisp, unrelated to the Apple Macintosh which came twenty years later), imitated this feature from InterLisp (another one of the significant predecessors).
Little details like this make the difference between pleasant programming and swearing at the monitor: see for instance A Short Ballad Dedicated to the Growth of Programs inspired by one Lisp programmer's struggle with a bletcherous dialect in which empty lists cannot be accessed with car
, and do not serve as a boolean false.