[Grace-core] puzzles with outer and confidential

Kim Bruce kim at cs.pomona.edu
Wed Jul 24 11:41:40 PDT 2013


I have a short program that exhibits a couple of issues with the current definition and implementation of "outer" in Grace:

def y = -4
var x := object {
    def y is confidential = 3
    var v := 1
    method m(z) {
        def y = 5
        print (self.y)
        print(outer.y)
    }
    def o = object{
    }
}
def z = 2
print(x.o.outer.y)
print(x.m(23))

This program compiles and runs find under minigrace (Standard visibility) with output:
3
3
-4

Here are the issues:
1) x.o.outer.y is a legal expression and returns the value 3 even though y is a confidential item in object x.  I claim that this is an error.  I believe the rule that we had talked about is that confidential items were only accessible via self, super, and (some number of) outers.  The key is that the chain that leads up to outer must only have other outers or self or super on it.  Hopefully this is easily detectable (and fixable).

2.) This is more substantive as it has to do with the semantics of outer.  (Note: "outer" is only mentioned as a keyword in the spec, but there is no indication of its semantics.)  The question has to do with method m of object x.  The meaning of self.y is obviously the value 3 given in the declaration of the object (and definitely not the local def in the method).  But what is the meaning of outer.y?  I would have expected outer to be the scope outside of the current scope.  That is, I would have expected it to be the scope on the inside of the object.  Instead this returns the y defined outside the object.  In other words, it returns the scope outside of the one where self is defined.

It's not clear to me which is more intuitive, especially when we look at situations involving blocks, where we are already mangling definitions of self and return to give appropriate behavior.

A plus for the definition of outer meaning the scope outside the current one is that it is easy to explain.  It is also easy to stack up several if we wanted to go out further.  Thus I would have written outer.outer.y in the body of m to access the y defined outside the object.

A plus for the definition of the scope outside the place where self is defined is that there is no overlap between self and outer -- they always refer to different scopes.

I'm sure there are other considerations.  We should all come to an agreement as to what outer actually means and document it in the spec.

Kim





More information about the Grace-core mailing list