[Top][All Lists]

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

Re: plist-put modification by side effect

From: Dan Davison
Subject: Re: plist-put modification by side effect
Date: Sun, 1 Feb 2009 11:23:14 -0500
User-agent: Mutt/1.5.18 (2008-05-17)

On Sun, Feb 01, 2009 at 12:02:42AM +0100, Thien-Thi Nguyen wrote:
> () Dan Davison <address@hidden>
> () 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.


> thi


reply via email to

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