Message from discussion Destructive Side Effects
From: Kent M Pitman <pit...@world.std.com>
Subject: Re: Destructive Side Effects
Date: Sat, 17 Nov 2001 20:31:41 GMT
References: <mMxJ7.firstname.lastname@example.org> <email@example.com> <KjyJ7.firstname.lastname@example.org> <email@example.com> <eczJ7.firstname.lastname@example.org>
Organization: My ISP can pay me if they want an ad here.
X-Newsreader: Gnus v5.7/Emacs 20.7
"David McClain" <bar...@qwest.net> writes:
> > don't use them! Please not too that most of CL's destructive functions
> > to be used in a functional way (you have to use the return value). The
> Actually, this is one of the surprising things about REMF that caught my
> attention. You are correct that most often destructive operations in Lisp
> operate in a functional manner... except for REMF (and no doubt a few
Well, from a philosophical point of view, it's generally important
that this BE destructive. The whole point of properties is to
implement a kind of blackboard approach to programming, and the idea
of having a bunch of people working on a shared blackboard with only
copying-assignment available is pretty odd. By reverse induction (if
there is such a thing), all plists would be always empty.
I'm not saying there's never a reason to want to spawn a separate plist,
but I don't think it's the norm.
Similarly, one doesn't have destruction-free hash tables either.
It is true that REMOVE is a possible operation on alists, but in practice
it's very rare for me to use such a thing... You never know how long an
alist will be and it's a good way to get O(n^2) behavior if you go randomly
copying all its elements to do something. We just saw someone here the other
day who was implementing (cdr (assoc 'foo x)) as
(cadar (remove-if-not #'(lambda (key) (eq key 'foo)) x :key #'car))
or some such thing. Saying that people should program in a side-effect-free
way creates situations where people do this kind of thing.
I know there are languages where this kind of thing is done routinely.
MOO does all side-effects to lists (which it implements more like vectors)
by copying. But then, while MOO is very pleasant to program in for small
problems, it is not known for its ability to enable programmers with the
full computational speed of the underlying machine. Lists are only second
class data in MOO, and really have no identity.
And perhaps there are FP languages that secretly do better by doing the dirty
side-effects invisibly so you don't have to see them. Ultimately, assembly
code ALWAYS works by side-effect, after all. Everything above the basic memory
model of the machine that suggests otherwise is an illusion.