[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Side effecting constants inside functions
- To: TIM@MIT-MC.ARPA, common-lisp@SU-AI.ARPA
- Subject: Re: Side effecting constants inside functions
- From: Masinter.pa@Xerox.ARPA
- Date: Mon, 02 Sep 1985 21:53:00 -0000
- In-reply-to: Charles Hornig <Hornig@SCRC-STONY-BROOK.ARPA>'s message of Mon, 26 Aug 85 10:36 EDT
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.