[Grace-core] minigrace oddness

James Noble kjx at ecs.vuw.ac.nz
Mon Jun 30 02:19:07 PDT 2014


On 30/06/2014, at 12:27 pm, Andrew P Black <black at cs.pdx.edu> wrote:

> Ugh!  Why not give the object a name?

Short answer - you can always write 

    def x = object { ... } 

but it doesn't always do what you want (in that x.foo will make a
normal "external" request on x, coming down from x's outside,
not an "outer" request on x, coming up from x's inside. 


Longer answer: other constructors (literals) don't have names.
But I guess we could add internal names for objects. 
The syntax is obvious (from OCAML):

object myname is annotations {

}


where "myname" can be used as an alias for "self" inside the object,
and the appropriate number of outer"s in objects nested inside.

But this means that the syntatic form of a message request "myname.foo"
*isn't* a "normal" request when myname is one of these nested names,
it has to have the semantics of an "outer" request.    
That's confusing (although a further syntax would be to force people to write 
outer(myname) or outer.myname which have the virtue of not looking like
normal method requests

I also think that people will want to write code referencing myname, i
i.e. that the named constructor also induces a declaration like 

def myname = object myname { ... } 

as in Scala.   (or perhaps they won't - I don't think OCAML does this,
and it does have named objects and named classes).   Do we allow this? 

At which point, if anything, I quite like generalising "outer" to work like "super";
you're only allowed one "outer" (you can't write outer.outer or super.super);
and outer *must* be followed by a request, that is just looked up lexically.
If you want a reference to an outer object to hand out, use a def.
If you want to call a confidential method that's lexically shadowed, 
outside you, you can't --- just as in Smalltalk, you can't call a 
normally requests a method from some super-super class that
e.g. your superclass has overridden.

one point seems to be that minigrace itself doesn't use "outer." at all
so we could change this without the existing compiler relying on it...

J




More information about the Grace-core mailing list