From rgentlem at fhcrc.org  Tue Feb  8 23:04:41 2005
From: rgentlem at fhcrc.org (Robert Gentleman)
Date: Tue Feb  8 23:05:02 2005
Subject: [Rd] Environment with no parent?
In-Reply-To: <x24qgmojys.fsf@biostat.ku.dk>
References: <nl2i01h7pffsdrsmrfoft00ro069e5n8cu@4ax.com>
	<x24qgmojys.fsf@biostat.ku.dk>
Message-ID: <6EA8BCBF-7A1D-11D9-8C28-000D933DC9FE@fhcrc.org>


On Feb 8, 2005, at 12:49 PM, Peter Dalgaard wrote:

> Duncan Murdoch <murdoch@stats.uwo.ca> writes:
>
>> Looking in envir.c, I see this:
>>
>>     /* env is now R_NilValue, the base environment */
>>
>> which doesn't give me much hope, but maybe there's a trick....
>>
>> If not, would it be reasonable to install a magic "EmptyEnv" to use as
>> a parent in this sort of situation?
>>
>
> I'm fairly sure the answer is "nope".
>
> It's been annoying me for years, for language aesthetic reasons
> mostly, but also with some consideration of cases like yours, and I've
> been on the brink of implementing a version where the base environment
> was a true environment. Apart from the usual issue of "round tuits",
> I was held back by the fact that one has to consider at least two  
> things:
>
> (a) efficiency. Is it expensive no longer to have the base functions
> bound directly to their symbol? (My gut feeling is that with suitable
> hashing and cacheing, the penalty is minimal.)
>
> (b) you can *only* use get and simple variable retrieval in a non-base
> environment with a NULL parent (eval(x <- 1, envir=foo) would give
> 'couldn't find function "<-"' or so). This could cause some confusion.


   And, I think, that a better approach is to implement a proper hash  
table class
and to then implement environments as hash table + parent (rather than  
the
current version, which would be environment  - parent), but the tuit  
shortage is devastating on this side of the atlantic (possibly due to  
the disadvantageous $/euro exchange rate; I'm sure you all can afford  
more of them :-))

  Robert


>
>
> --  
>    O__  ---- Peter Dalgaard             Blegdamsvej 3
>   c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
>  (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
+----------------------------------------------------------------------- 
----------------+
| Robert Gentleman              phone: (206) 667-7700                    
          |
| Head, Program in Computational Biology   fax:  (206) 667-1319   |
| Division of Public Health Sciences       office: M2-B865               
       |
| Fred Hutchinson Cancer Research Center                                 
          |
| email: rgentlem@fhcrc.org                                              
                          |
+----------------------------------------------------------------------- 
----------------+


[Rd] Environment with no parent?
Robert Gentleman