From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: plist-put: destructive? Date: Sat, 21 Jan 2017 09:13:09 +0100 Message-ID: <20170121081309.GB11931@tuxteam.de> References: <87mvelzgrr.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; x-action=pgp-signed X-Trace: blaine.gmane.org 1484986439 19834 195.159.176.226 (21 Jan 2017 08:13:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 21 Jan 2017 08:13:59 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 21 09:13:55 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cUqo0-0004EL-Ee for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 09:13:48 +0100 Original-Received: from localhost ([::1]:59125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUqo5-0007Y1-2j for geh-help-gnu-emacs@m.gmane.org; Sat, 21 Jan 2017 03:13:53 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40280) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cUqna-0007Xt-DQ for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 03:13:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cUqnX-0006ca-6l for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 03:13:22 -0500 Original-Received: from mail.tuxteam.de ([5.199.139.25]:36692 helo=tomasium.tuxteam.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cUqnX-0006Zq-0u for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 03:13:19 -0500 Original-Received: from tomas by tomasium.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1cUqnN-0003Gt-D6 for help-gnu-emacs@gnu.org; Sat, 21 Jan 2017 09:13:09 +0100 In-Reply-To: <87mvelzgrr.fsf@ericabrahamsen.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 5.199.139.25 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112134 Archived-At: -----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-----