[Top][All Lists]

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

RE: Is `eval' allowed to modify its argument?

From: Drew Adams
Subject: RE: Is `eval' allowed to modify its argument?
Date: Fri, 13 Nov 2020 15:14:47 -0800 (PST)

> Destructive operations on lists, like `nreverse` or `sort` should (as
> a general rule) only ever be used on lists you yourself just
> constructed (so you can be (almost) 100% sure you hold the one
> and only reference to the list and nobody else will be able to
> witness the destructiveness).
> Using it on something you received as an argument is basically always
> a bug, unless it's clearly documented (as is done, for example, in the
> doc of `nreverse`).
> PS: The "almost" above is because in Elisp you can't really be sure of
>     anything, thanks to things like advice.  That's why users of advice
>     are warned that it's up to them to deal with any problem that may
>     result of poor interaction between their code and the rest.

+1.  I was going to say about the same thing.

Safest is local to a function or other context
(e.g. `let' lexical binding).

But there are use cases for modifying a part
of a global structure.

In that case, as in all cases, it's generally
more likely that you'll step on your own toes
than that someone else will step on them.  One
part of you or your code will forget or not
realize that something you use is susceptible
to your code modifying it ... gotcha!

IOW, modifying only stuff that _you_ create
doesn't guard against your own worst enemy -
yourself at another time or in a different

And the effect isn't always easy to detect
immediately or the cause easy to localize.
Really modifying data (i.e., "destructively")
is a different world - not for the faint of
heart. ;-)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]