help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: plist-put: destructive?


From: tomas
Subject: Re: plist-put: destructive?
Date: Sat, 21 Jan 2017 09:13:09 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Fri, Jan 20, 2017 at 11:13:28AM -0800, Eric Abrahamsen wrote:
> Plists are great, except for setting keys, which isn't great.
> Occasionally it annoys me enough to want to try to "do something" about
> it.
> 
> The docstring for plist-put says we should be using:
> 
> (setq some-plist (plist-put some-plist :prop val))
> 
> To be sure of modifying the list correctly. But all my experiments have
> shown that a plain plist-put does modify the original list, and
> everything works as expected without re-assigning to the original
> variable.
> 
> So what's the ambiguity? Are there circumstances where a simple
> plist-put isn't going to modify the original plist?
> 
> I tried this:
> 
> (gv-define-simple-setter plist-get plist-put)
> 
> Which allows this to work:
> 
> (setf (plist-get some-plist :prop) val)
> 
> That's hardly less verbose than the setq re-assignment, but I suppose it
> would allow for a plist to be used in cl-letf, or for a custom macro
> like:
> 
> (with-plist-props ((prop1 :prop1) (prop2 :prop2)) some-plist
>   ...)
> 
> But if plist-put is reliably destructive, I don't suppose any of that is
> really necessary.
> 
> Can we rely on plist-put?

Try starting with an empty plist

(IOW: plist-put is destructive if it has something to tack the new pair
on. Otherwise it can't. Perhaps the above if can be made into an iff)

regards
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAliDGBUACgkQBcgs9XrR2kYH4QCfaayFmENHeH8Hsai9zWhJoGZ/
a3gAn1BMdM4EKJAS+cEkaNUmKavWu3hj
=uxIG
-----END PGP SIGNATURE-----



reply via email to

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