[Grace-core] Semantics of object/classes

James Noble kjx at ecs.vuw.ac.nz
Wed Aug 8 23:11:13 PDT 2012


On 9/08/2012, at 13:57 PM, Marco Servetto wrote:

>> object { inherits X D... }  //  "inserts" all parts of the object described by D into X
> 
> For a complete "inherit from objects" semantic, this design require
> objects to be dynamically enriched.

if we allow general inheritance from any object, yes.
If only from some kind of "factory method" or "class" that 
encapsulates and returns an object constructor, then no.

> In particular, one can write the following "multiple inheritance" code.
> 
> def obj0 = object { D0 }
> def obj1 = object { inherits obj0 D1 }
> def obj2 = object { inherits obj0 D2 }
> 
> And now our obj0 should contains the combination of D0, D1 and D2 in this order.
> obj0, obj! and obj2 are all alias for the same object.

right. Which will be really confusing, especially with that syntax.

> This semantic is very different from "delegation", is probably harder
> to implement but avoid the creation - possible exposure of many
> different object.

right. which is what we're after.

> The only other way (that I can imagine) to have a complete "inherit
> from objects" semantic and ensuring no exposure of delegated object is
> the automatic cloning.

Again, I don't like automatic or implicit anything, especially not when 
a fundamental part of the language (inheritance) will call out to user code.

Just doing a shallow clone is wrong, adding ownership and an ownership based
clone is research.  I still hope (vainly) that we can do without a build-in, generic 
clone on all or most objects. 

But the an "inherit only from encapsulated object constructors" does almost what we 
want: if you think about writing a clone method, in Grace it would have to return an object 
constructor --- so we should always be able to inherit from an *explicit* clone - and I'm
happy to inherit from that explicit clone. 

James


More information about the Grace-core mailing list