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

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

Re: Is it safe to modify a property list directly with PLIST-PUT?


From: Teemu Likonen
Subject: Re: Is it safe to modify a property list directly with PLIST-PUT?
Date: Mon, 27 Jul 2009 08:59:18 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux)

On 2009-07-26 22:07 (+0200), Pascal J. Bourguignon wrote:

> Teemu Likonen <tlikonen@iki.fi> writes:
>>     (setq my-data '((:foo "one" :bar "two")
>>                     (:foo "three" :bar "four")))
>
> It is never safe to modify literal data!

Oh yes, that was a stupid example. MY-DATA is not really created that
way. We can assume this:

>      (setq my-data (list (list :foo "one" :bar "two")
>                          (list :foo "three" :bar "four")))

> Notice also that like delete, plist-put returns the result, it cannot
> always modify the property list in place.  So you have to restore the
> result:
>
>    (setf (nth 1 my-data) (plist-put (nth 1 my-data) :bar "New value"))

Thanks. Now, let's go one step further while still assuming that we are
not using Emacs CL extension (perhaps just for my education). Is this
reliable:

    (let ((item (nth 1 my-data)))
      (setq item (plist-put item :bar "New value")))

At least it seems to be working: the change appears in MY-DATA too:

    ((:foo "one" :bar "two")
     (:foo "three" :bar "New value"))


reply via email to

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