[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Side effecting constants inside functions

What's wrong with this style? Normally, there's an invariant that
running a piece of code doesn't change its semantics, or how it prints
out. The example you gave violates that invariant, and thus seems
clearly to be "bad style". (A lot of things attributed to "style"
actually have good reasons behind them, if you think about it.) (Your
example doesn't act like a lexical closure because its not reentrant.)

Here's a more reasonable, although not compelling, example.

(defmacro compute-once (form)
   `(let ((value '(,nil . ,nil)))
      (cond ((car value) (cdr value))
              (t (setf (car value) t)
                 (setf (cdr value) ,form))))

(compute-once <compute-stuff>) executes <compute-stuff> once, the first
time it is run.

Well, its a more reasonable example... I have to admit that I thought it
was pretty awful when I first saw it, but then, that's what I thought of
#. too.