all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Eric Abrahamsen <eric@ericabrahamsen.net>, help-gnu-emacs@gnu.org
Subject: RE: plist-put: destructive?
Date: Sat, 21 Jan 2017 09:13:02 -0800 (PST)	[thread overview]
Message-ID: <b3c1104b-54e0-4fb0-ade8-034812a86de4@default> (raw)
In-Reply-To: <8737gcxt4e.fsf@ericabrahamsen.net>

> Thanks to you both. I'm working with existing plists, so I'll drop
> the setqs, that's a relief.

Why is it a relief - a relief from what?  What if something reset your "existing plist" to nil behind your back?

Setting (again) a variable whose value is an object to which you've applied a destructive operation is the standard idiom.  And it is good programming practice.  It ensures that your code does what you expect, regardless of the object value, or rather, regardless of the effect of the operation.

You naturally think of your variable as always pointing to the object that you expect.  To keep this relationship, you must set the variable to the return value of any destructive operation.

This is true for a possibly "destructive" operation on any kind of object.  The poster-child case is a list.  See, for example, (elisp) `Rearrangement' (http://www.gnu.org/software/emacs/manual/html_node/elisp/Rearrangement.html).

The point is that your variable is otherwise not guaranteed to continue to point to the object that you think it does.  You need to set it to the _result_ of the possibly destructive operation (the return value), if you really want the variable to take the effect of that operation into account.

This is all about the difference between a variable and its object value.



  reply	other threads:[~2017-01-21 17:13 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-20 19:13 plist-put: destructive? Eric Abrahamsen
2017-01-21  3:25 ` Stefan Monnier
2017-01-21 10:25   ` tomas
2017-01-21 16:41   ` Eric Abrahamsen
2017-01-21 17:13     ` Drew Adams [this message]
2017-01-22  0:50       ` Eric Abrahamsen
2017-01-22 10:08         ` Philipp Stephani
2017-01-22 13:10           ` Eric Abrahamsen
2017-01-22 17:30         ` Stefan Monnier
2017-01-23  0:31           ` Eric Abrahamsen
2017-01-23  9:01           ` tomas
2017-01-21 23:03     ` Stefan Monnier
2017-01-22  1:15       ` Eric Abrahamsen
2017-01-21  8:13 ` tomas

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=b3c1104b-54e0-4fb0-ade8-034812a86de4@default \
    --to=drew.adams@oracle.com \
    --cc=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@gnu.org \
    /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.