Well, one difference exists—literal objects such as quoted lists, but also including double-quoted strings, literal arrays, and vectors (whose syntax you'll see later), must not be modified. Consequently, any lists you plan to manipulate you should create with LIST
.
50
This syntax is an example of a
51
People without experience using Lisp's macros or, worse yet, bearing the scars of C preprocessor-inflicted wounds, tend to get nervous when they realize that macro calls look like regular function calls. This turns out not to be a problem in practice for several reasons. One is that macro forms are usually formatted differently than function calls. For instance, you write the following:
(dolist (x foo)
(print x))
rather than this:
(dolist (x foo) (print x))
or
(dolist (x foo)
(print x))
the way you would if DOLIST
was a function. A good Lisp environment will automatically format macro calls correctly, even for user-defined macros.
And even if a DOLIST
form was written on a single line, there are several clues that it's a macro: For one, the expression (x foo)
is meaningful by itself only if x
is the name of a function or macro. Combine that with the later occurrence of x
as a variable, and it's pretty suggestive that DOLIST
is a macro that's creating a binding for a variable named x
. Naming conventions also help—looping constructs, which are invariably macros—are frequently given names starting with
52
Using the empty list as false is a reflection of Lisp's heritage as a list-processing language much as the use of the integer 0 as false in C is a reflection of its heritage as a bit-twiddling language. Not all Lisps handle boolean values the same way. Another of the many subtle differences upon which a good Common Lisp vs. Scheme flame war can rage for days is Scheme's use of a distinct false value #f
, which isn't the same value as either the symbol nil
or the empty list, which are also distinct from each other.
53
Even the language standard is a bit ambivalent about which of EQ or EQL should be preferred. Object identity is defined by EQ, but the standard defines the phrase the same when talking about objects to mean EQL unless another predicate is explicitly mentioned. Thus, if you want to be 100 percent technically correct, you can say that (- 3 2) and (- 4 3) evaluate to 'the same' object but not that they evaluate to 'identical' objects. This is, admittedly, a bit of an angels-on-pinheads kind of issue.
54
Despite the importance of functions in Common Lisp, it isn't really accurate to describe it as a
55
Well, almost any symbol. It's undefined what happens if you use any of the names defined in the language standard as a name for one of your own functions. However, as you'll see in Chapter 21, the Lisp package system allows you to create names in different namespaces, so this isn't really an issue.
56
Parameter lists are sometimes also called
57
For example, the following:
(documentation 'foo 'function)
returns the documentation string for the function foo
. Note, however, that documentation strings are intended for human consumption, not programmatic access. A Lisp implementation isn't
58