From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Davison Newsgroups: gmane.emacs.help Subject: Re: plist-put modification by side effect Date: Sun, 1 Feb 2009 11:23:14 -0500 Message-ID: <20090201162314.GA13754@stats.ox.ac.uk> References: <20090131210630.GC17573@stats.ox.ac.uk> <87d4e3w031.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1233505457 2389 80.91.229.12 (1 Feb 2009 16:24:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Feb 2009 16:24:17 +0000 (UTC) Cc: help-gnu-emacs mailing list To: Thien-Thi Nguyen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 01 17:25:28 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1LTf8O-0006KV-KC for geh-help-gnu-emacs@m.gmane.org; Sun, 01 Feb 2009 17:25:24 +0100 Original-Received: from localhost ([127.0.0.1]:37330 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LTf76-00086q-1P for geh-help-gnu-emacs@m.gmane.org; Sun, 01 Feb 2009 11:24:04 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LTf6P-0007xC-Hs for help-gnu-emacs@gnu.org; Sun, 01 Feb 2009 11:23:21 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LTf6N-0007vY-O3 for help-gnu-emacs@gnu.org; Sun, 01 Feb 2009 11:23:21 -0500 Original-Received: from [199.232.76.173] (port=33083 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LTf6N-0007vK-Ey for help-gnu-emacs@gnu.org; Sun, 01 Feb 2009 11:23:19 -0500 Original-Received: from markov.stats.ox.ac.uk ([163.1.210.1]:54017) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LTf6L-0007Ro-OY for help-gnu-emacs@gnu.org; Sun, 01 Feb 2009 11:23:18 -0500 Original-Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id n11GNGeo014694; Sun, 1 Feb 2009 16:23:16 GMT Original-Received: by blackcap.stats.ox.ac.uk (Postfix, from userid 5158) id 42D47180A5; Sun, 1 Feb 2009 16:23:16 +0000 (GMT) Mail-Followup-To: Thien-Thi Nguyen , help-gnu-emacs mailing list Content-Disposition: inline In-Reply-To: <87d4e3w031.fsf@ambire.localdomain> User-Agent: Mutt/1.5.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: Solaris 8 (1) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:61834 Archived-At: On Sun, Feb 01, 2009 at 12:02:42AM +0100, Thien-Thi Nguyen wrote: > () Dan Davison > () Sat, 31 Jan 2009 16:06:30 -0500 > > I don't get this. It says the plist is altered by side > effects. So what's with the "but just to be extra careful > use (setq ...)" advice? > > If PROP is in PLIST, the natural side-effecting operation is > to splice in the VALUE at the position of the old value. Ok, > fine. Now, what if PROP is not in PLIST? How might you > implement that? How might you implement that, differently? > How might your design decision surprise the unwary caller? > Thanks Thi and Helmut for your answers. Let me see if can answer the questions Thi set me. If PROP is not in PLIST, then I guess the two possibilities you are referring to are 1. add PROP with value VAL to head of PLIST 2. add PROP with value VAL to tail of PLIST and only in case 2 will PLIST be altered by side-effect. So if I've understood this then I think the docstring is inaccurate since `The PLIST is modified by side effects.' is not necessarily true. I also think it would be helpful if the docstring spelled things out more. I'd suggest something like Change value in PLIST of PROP to VAL. PLIST is a property list, which is a list of the form (PROP1 VALUE1 PROP2 VALUE2 ...). PROP is a symbol and VAL is any object. If PROP is already a property on the list, its value is set to VAL. Otherwise the new PROP VAL pair is added; in this case PLIST (if non-nil) may be modified by side effects, although this cannot be relied upon. Therefore use `(setq x (plist-put x prop val))' to be sure to use the new value. Dan > thi > -- http://www.stats.ox.ac.uk/~davison