From pdalgd at gmail.com  Thu Nov 24 15:45:38 2011
From: pdalgd at gmail.com (peter dalgaard)
Date: Thu, 24 Nov 2011 15:45:38 +0100
Subject: [Rd] Confused about NAMED
In-Reply-To: <0feab74fdda903967fff2f6868d8cf75.squirrel@webmail.plus.net>
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>
Message-ID: <4372BFDD-E75E-4459-B662-534D5521979C@gmail.com>


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.

-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



[Rd] Confused about NAMED
peter dalgaard