From Waclaw.Marcin.Kusnierczyk at idi.ntnu.no  Fri Mar 13 21:39:37 2009
From: Waclaw.Marcin.Kusnierczyk at idi.ntnu.no (Wacek Kusnierczyk)
Date: Fri, 13 Mar 2009 21:39:37 +0100
Subject: [Rd] surprising behaviour of names<-
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D700DF10EE@NA-PA-VBE03.na.tibco.com>
References: <49B67CB1.8060005@idi.ntnu.no>	<49B682F9.8050307@biostat.ku.dk>	<49B6E6D9.7010809@idi.ntnu.no>	<96A4BB14-D6EA-44B1-B524-6DB139F3A7F8@r-project.org>	<8CCAAAD3-919F-462F-A616-F4FDDB46D975@r-project.org>	<49B81186.4070107@idi.ntnu.no>	<20090312154008.56706f38@berwin-nus1>	<49B8D060.8090206@idi.ntnu.no>	<20090312173231.7a2929df@berwin-nus1>	<49B8DB8F.5030704@idi.ntnu.no>	<20090312213508.719afa73@berwin5>	<49B91A7E.50107@idi.ntnu.no>	<20090312231240.6a061f0b@berwin5>	<49B96FE7.2060705@idi.ntnu.no>	<20090313120309.7acb13e5@berwin-nus1>	<49BA38EB.3000004@idi.ntnu.no><20090313234755.6f6e08c9@berwin5>	<49BAA8E6.3080407@idi.ntnu.no>
	<77EB52C6DD32BA4D87471DCD70C8D700DF10EE@NA-PA-VBE03.na.tibco.com>
Message-ID: <49BAC489.7070006@idi.ntnu.no>

William Dunlap wrote:
> Would it make anyone any happier if the manual said
> that the replacement functions should not be called
> in the form
>    xNew <- `func<-` (xOld, value)
> and should only be used as
>    func(xToBeChanged) <- value
>   

surely better than guesswork.

> ? 
>
> The explanation
>       names(x) <- c("a","b")
>   is equivalent to
>       '*tmp*' <- x
>       x <- "names<-"('*tmp*', value=c("a","b"))
> could also be extended a bit, adding a line like
>       rm(`*tmp*`)
> Those 3 lines should be considered an atomic operation:
> the value that `*tmp*` or `x` may have or what is
> in the symbol table at various points in that sequence 
> is not defined.  (Letting details be explicitly undefined
> is important: it gives developers room to improve the
> efficiency of the interpreter and tells users where not to go.) 
>   

there is a difference between letting things be undefined and explicitly
stating that things are unspecified.  the c99 standard [1], for example,
is explicit about the non-determinism of expressions that involve side
effects, as it is about that some expressions may actually not be
evaluated if the optimizer decides so. 

berwin has already suggested that one reads from what docs do *not*
say;  it's a very bad idea.  it's best that the documentation *does* say
that, for example, a particular function should be used only in the
infix form because the semantics of the prefix form are not guaranteed
and may change in future versions.

if the current state is that 'names<-' will modify the object it is
given as an argument in some situations, but not in others, and this is
visible to the user, the best thing to do is to give an explicit warning
-- perhaps with an annotation that things may change, if they may.

best,
vQ


[1] http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf



[Rd] surprising behaviour of names<-
Wacek Kusnierczyk