From ggrothendieck at gmail.com  Wed Oct 17 17:07:14 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 17 Oct 2007 11:07:14 -0400
Subject: [Rd] LazyLoad changes the class of objects
In-Reply-To: <59d7961d0710170741k4b25359cjdbdfcb77f772b87f@mail.gmail.com>
References: <971536df0710120004k236f017je01153dcf55869dd@mail.gmail.com>
	<Pine.LNX.4.64.0710170759210.12037@nokomis.stat.uiowa.edu>
	<59d7961d0710170741k4b25359cjdbdfcb77f772b87f@mail.gmail.com>
Message-ID: <971536df0710170807x1f896c0bo98ad91e7a8a0164c@mail.gmail.com>

On 10/17/07, Henrik Bengtsson <hb at stat.berkeley.edu> wrote:
> Yes (on the yes), to second Luke.  Here is John Chambers' comment when
> I was bitten by the same "bug" a while ago:
>
>  http://tolstoy.newcastle.edu.au/R/devel/02b/0524.html
>
> See also Peter Dalgaard's follow up suggesting to wrap up the
> environment in a list, which will typically be enough.  I've been
> using this "trick" successfully in the Object class (R.oo package) for
> several years, where I'm putting the environment in the attributes
> list of an object, i.e.  obj <- NA; attr(NA, "..env") <- new.env();
> It turned out at the time that this was slightly faster to access than
> using a list element.

This has all been discussed before but this "trick" is not sufficient
for defining an environment subclass because it does not respect
inheritance.  The subclass writer must replicate all methods that
act on environments in a subclass for an environment subclass to
have them.  Inheritance is completely broken.

If there were N environment methods the writer of an environment subclass
would have to write N methods to support them all.  On the other hand,
if it worked in a true OO way the subclass writer would not have to write
anything.

Also suppose a new environment method comes along.  In true OO
the subclass automatically inherits it but with the "trick" the subclass
writer needs to write a new method always mimicing the parent.

This is not how OO is supposed to work.



[Rd] LazyLoad changes the class of objects
Gabor Grothendieck