all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>, help-gnu-emacs@gnu.org
Subject: RE: Is `eval' allowed to modify its argument?
Date: Fri, 13 Nov 2020 15:14:47 -0800 (PST)	[thread overview]
Message-ID: <e2f2eb95-aae2-4cbb-ba94-3805b174193f@default> (raw)
In-Reply-To: <jwv7dqouaqq.fsf-monnier+emacs@gnu.org>

> 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
context.

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	other threads:[~2020-11-13 23:14 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 21:06 Is `eval' allowed to modify its argument? Michael Heerdegen
2020-11-12 21:18 ` Michael Heerdegen
2020-11-12 22:13 ` Stefan Monnier
2020-11-13 11:29   ` Michael Heerdegen
2020-11-13 14:12     ` Stefan Monnier
2020-11-13 18:56       ` Michael Heerdegen
2020-11-13 23:01         ` Stefan Monnier
2020-11-13 23:14           ` Drew Adams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2f2eb95-aae2-4cbb-ba94-3805b174193f@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.