This passage from On Lisp
is genuinely confusing -- it is not clear how returning a quoted list such as '(oh my)
can actually alter how the function behaves in the future: won't the returned list be generated again in the function from scratch, the next time it is called?
If we define exclaim so that its return value incorporates a quoted list,
(defun exclaim (expression) (append expression ’(oh my)))
Then any later destructive modification of the return value
(exclaim ’(lions and tigers and bears)) -> (LIONS AND TIGERS AND BEARS OH MY) (nconc * ’(goodness)) -> (LIONS AND TIGERS AND BEARS OH MY GOODNESS)
could alter the list within the function:
(exclaim ’(fixnums and bignums and floats)) -> (FIXNUMS AND BIGNUMS AND FLOATS OH MY GOODNESS)
To make exclaim proof against such problems, it should be written:
(defun exclaim (expression) (append expression (list ’oh ’my)))
How exactly is that last call to exclaim
adding the word goodness
to the result? The function is not referencing any outside variable so how did the separate call to nconc
actually alter how the exclaim
function works?