================================================================== Hunk E starts here: ==================================================================
In Scheme, there is one null pointer value, called "the empty list,"
which prints as ()
. (Later, we'll see why it's written that
way, and why it's called "the empty list.")
Conceptually, the empty list is a special object, and a "null" pointer is a pointer to this special end-of-list object. You can ignore that fact and think of it as just a null pointer, because there's nothing interesting you can do with the object it points to.
(In some implementations, the empty list object '()
is actually an
object referred to via a pointer, and null pointers are really pointers
to it. In others, an empty list is an immediate value, a specially tagged
null pointer. At the level of the Scheme language, it doesn't matter which
way it's implemented in a particular Scheme system. All you can really do
with the null pointer is compare it against other pointers, to see if
they're null pointers, too.)
The empty list object acts as a null pointer for any purpose--there's only one kind of pointer (pointer to anything), so there's only one kind of null pointer (pointer to nothing).
Scheme provides a procedure, null?
to check whether a value
is (a pointer to) the empty list, i.e., a null pointer. For example,
(null? foo)
returns #t
if the value of the variable
foo
is the empty list, and #f
otherwise.
You might be wondering why the null pointer object is called "the empty list"; we'll explain that later. Given the way lists are usually used in Scheme, it turns out to make perfect sense.
You can write the empty list as a literal in your programs as '()
.
That is, the expression '()
returns the empty list (null pointer),
()
. Later we'll explain why you have to put the single quote mark
in front of the empty set of parentheses when writing the empty list as
a literal.