[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: plist-put: destructive?
From: |
Drew Adams |
Subject: |
RE: plist-put: destructive? |
Date: |
Sat, 21 Jan 2017 09:13:02 -0800 (PST) |
> 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.
- plist-put: destructive?, Eric Abrahamsen, 2017/01/20
- Re: plist-put: destructive?, tomas, 2017/01/21
- Re: plist-put: destructive?, Stefan Monnier, 2017/01/21
- Re: plist-put: destructive?, tomas, 2017/01/21
- Re: plist-put: destructive?, Eric Abrahamsen, 2017/01/21
- Re: plist-put: destructive?, Stefan Monnier, 2017/01/22
- Re: plist-put: destructive?, Eric Abrahamsen, 2017/01/22
- Re: plist-put: destructive?, tomas, 2017/01/23
- Re: plist-put: destructive?, Stefan Monnier, 2017/01/21
- Re: plist-put: destructive?, Eric Abrahamsen, 2017/01/22