From mdowle at mdowle.plus.com  Thu Nov 24 16:56:45 2011
From: mdowle at mdowle.plus.com (Matthew Dowle)
Date: Thu, 24 Nov 2011 15:56:45 -0000
Subject: [Rd] Confused about NAMED
In-Reply-To: <4372BFDD-E75E-4459-B662-534D5521979C@gmail.com>
References: <719cbc60d789ea0d3bf1d6a18309a216.squirrel@webmail.plus.net>
	<090530A4-BBC5-48B3-9EC0-2D965C200729@gmail.com>
	<2573e1d2e510477135f6246e60d53aef.squirrel@webmail.plus.net>
	<A46434F9-309A-4D83-A5F1-54472DE36FDE@gmail.com>
	<0feab74fdda903967fff2f6868d8cf75.squirrel@webmail.plus.net>
	<4372BFDD-E75E-4459-B662-534D5521979C@gmail.com>
Message-ID: <7a32d6c690bcb77862375b2791888047.squirrel@webmail.plus.net>

>
> 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



[Rd] Confused about NAMED
Matthew Dowle