132
CONS
was originally short for the verb
133
When the place given to SETF
is a CAR
or CDR
, it expands into a call to the function RPLACA
or RPLACD
; some old- school Lispers—the same ones who still use SETQ
—will still use RPLACA
and RPLACD
directly, but modern style is to use SETF
of CAR
or CDR
.
134
Typically, simple objects such as numbers are drawn within the appropriate box, and more complex objects will be drawn outside the box with an arrow from the box indicating the reference. This actually corresponds well with how many Common Lisp implementations work—although all objects are conceptually stored by reference, certain simple immutable objects can be stored directly in a cons cell.
135
The phrase
136
The string functions NSTRING-CAPITALIZE
, NSTRING- DOWNCASE
, and NSTRING-UPCASE
are similar—they return the same results as their N-less counterparts but are specified to modify their string argument in place.
137
For example, in an examination of all uses of recycling functions in the Common Lisp Open Code Collection (CLOCC), a diverse set of libraries written by various authors, instances of the PUSH
/NREVERSE
idiom accounted for nearly half of all uses of recycling functions.
138
There are, of course, other ways to do this same thing. The extended LOOP
macro, for instance, makes it particularly easy and likely generates code that's even more efficient than the PUSH
/ NREVERSE
version.
139
This idiom accounts for 30 percent of uses of recycling in the CLOCC code base.
140
SORT
and STABLE-SORT
can be used as for-side-effect operations on vectors, but since they still return the sorted vector, you should ignore that fact and use them for return values for the sake of consistency.
141
NTH
is roughly equivalent to the sequence function ELT
but works only with lists. Also, confusingly, NTH
takes the index as the first argument, the opposite of ELT
. Another difference is that ELT
will signal an error if you try to access an element at an index greater than or equal to the length of the list, but NTH
will return NIL
.
142
In particular, they used to be used to extract the various parts of expressions passed to macros before the invention of destructuring parameter lists. For example, you could take apart the following expression:
(when (> x 10) (print x))
Like this:
;; the condition
(cadr '(when (> x 10) (print x))) ==> (> X 10)
;; the body, as a list