From jmc at r-project.org  Fri Jul  7 15:10:52 2006
From: jmc at r-project.org (John Chambers)
Date: Fri, 07 Jul 2006 09:10:52 -0400
Subject: [Rd] attributes of environments
In-Reply-To: <971536df0607051928m5017cd35xba788618cc6a36dc@mail.gmail.com>
References: <971536df0607042012h43eb1581n418e9cddfe3a51bb@mail.gmail.com>
	<5062E054-F56C-42AA-A446-BC53628DC189@r-project.org>
	<971536df0607051123p6f0eaf6chc9e50cfc72b0fe51@mail.gmail.com>
	<44AC110B.90306@stats.uwo.ca>
	<971536df0607051247p7f30412bs45c6cf81dfc16949@mail.gmail.com>
	<44AC1E8D.4000602@stats.uwo.ca>
	<971536df0607051333s51010444vecb09453717413c2@mail.gmail.com>
	<44AC2684.7060104@stats.uwo.ca>
	<971536df0607051706r13dcba67q6773f9e35ddb98f1@mail.gmail.com>
	<44AC7054.3070001@stats.uwo.ca>
	<971536df0607051928m5017cd35xba788618cc6a36dc@mail.gmail.com>
Message-ID: <44AE5D5C.4090403@r-project.org>

Umm, maybe we should step back a bit here.

There are two points being made, both of which I think are reasonable, 
but they just don't happen to work together.

1.  Environments are special objects in R.  In fact they are the 
essential way directly in R to implement reference semantics.  Every 
object that has an environment (say, as a slot), has the same object.  
Much of R depends on this semantic property.

2.  For any "class" in the language, it would be useful to define a 
class that extends (contains) that class, but has additional properties.

The essential reason 2 conflicts with 1 for environments is that slots 
and other properties of objects are implemented as attributes, including 
class(x).  Attributes are implemented inside the struct that holds the 
object itself.  This means you can not have an object of another class 
that contains an environment, in the same way you would with a 
non-reference object, without wiping out properties of the "contained" 
object.

You do get told this, in the  simplest case anyway.  For example, 
suppose I want a class that acts like an environment but also has a slot 
"source" for some extra information:

 > setClass("e2", representation(source="character"), contains = 
"environment")
[1] "e2"
Warning message:
class "environment" cannot be used as the data part of another class in: 
reconcilePropertiesAndPrototype(name, slots, prototype, superClasses, 

and indeed the new class doesn't work as you would expect.

So the question is whether we want to enforce that limitation, in which 
case we probably need a stronger slap on the wrist, or whether we should 
consider a different implementation for this case, to allow the new 
class to inherit the properties of an environment, without violating the 
integrity of environments.  I kind of like the second approach, but only 
if it does not overly mess with the general approach to classes.


Gabor Grothendieck wrote:

>On 7/5/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>  
>
>>On 7/5/2006 8:06 PM, Gabor Grothendieck wrote:
>>    
>>
>>>On 7/5/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>>      
>>>
>>>>On 7/5/2006 4:33 PM, Gabor Grothendieck wrote:
>>>>        
>>>>
>>>>>On 7/5/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>>>>          
>>>>>
>>>>>>On 7/5/2006 3:47 PM, Gabor Grothendieck wrote:
>>>>>>            
>>>>>>
>>>>>>>On 7/5/06, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
>>>>>>>              
>>>>>>>
>>>>>>>>On 7/5/2006 2:23 PM, Gabor Grothendieck wrote:
>>>>>>>>
>>>>>>>>                
>>>>>>>>

<etc.>

>______________________________________________
>R-devel at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-devel
>
>  
>



[Rd] attributes of environments
John Chambers