[Rd] Confused about NAMED
Matthew Dowle
mdowle at mdowle.plus.com
Thu Nov 24 16:56:45 CET 2011
>
> On Nov 24, 2011, at 14:05 , Matthew Dowle wrote:
>
>> Since list() is primitive I tried to construct a data.frame starting
>> with
>> list() [since structure() isn't primitive], but then merely adding an
>> attribute seems to set NAMED==2 too ?
>
> Yes. As soon as there is the slightest risk of having (had) two references
> to the same object NAMED==2 and it is never reduced. While your mind is
> boggling, I might boggle it a bit more:
>
>> z <- 1:10
>> .Internal(inspect(z))
> @116e11788 13 INTSXP g0c4 [NAM(1)] (len=10, tl=0) 1,2,3,4,5,...
>> m <- mean(z)
>> .Internal(inspect(z))
> @116e11788 13 INTSXP g0c4 [NAM(2)] (len=10, tl=0) 1,2,3,4,5,...
>
> This happens because while mean() is running, there is a second reference
> to z, namely mean's argument x. (With languages like R, you have no
> insurance that there will be no changes to the global environment while a
> function call is being evaluated, so bugs can bite in both places -- z or
> x.)
>
> There are many of these cases where you might pragmatically want to
> override the default NAMED logic, but you'd be stepping into treacherous
> waters. Luke has probably been giving these matters quite some thought in
> connection with his compiler project.
Ok, very interesting. Think I'm there.
Thanks for all the info.
Matthew
More information about the R-devel
mailing list