[Grace-core] Meaning of outer

Kim Bruce kim at cs.pomona.edu
Mon Aug 5 17:56:20 PDT 2013


I'm assuming we are meeting again tomorrow (Tuesday for me) at the same time as last week -- 3 p.m. my time.

I'd like us to think about the meaning of outer.  Here are some scenarios.  Some depend on shadowing of identifiers (something I believe we now allow, but many of us would like to remove).

1.  Look at the following example:

def y = 1
method m(z) {
       def y = 3
        object {
               def y = 5
               def w = outer.y
        }
 }

What does outer.y refer to?  My understanding is that it the object outside of the scope of the current self.  Thus it would refer to y = 3.  On the other hand, if we interpret as self.y for the outer scope (essentially outer.self.y), then it would refer to y = 1.  Which is correct?

2. What if the local  definition of y were removed?

def y = 1
method m(z) {
        object {
               def y = 5
               def w = outer.y
        }
 }

Does outer.y refer to y = 1?

Let's change the method to an object:

def y = 1
def ob = object {
        def u = object {
               def y = 5
               def w = outer.y
        }
 }

Does outer.y refer to y =1?  If we understand outer.y as self.y in the outer scope then it should be an error instead, as there is no top-level y in ob -- i.e., adding a new declaration:

def y = 1
def ob = object {
        var x := self.y
        def u = object {
               def y = 5
               def w = outer.y
        }
 }

The initialization of x to self.y is clearly erroneous as the self of ob has no y feature.  So is the reference to outer.y wrong for the same reason or does it just mean to start looking for y at the scope enclosing the current self.  E.g., clearly the following declaration of x is OK as it refers to y = 1:

def y = 1
def ob = object {
        var x := y
        def u = object {
               def y = 5
               def w = outer.y   ///???
        }
 }

For your information, minigrace seems to treat outer as the self for the next scope outside the current self's scope.  Thus the definition of w as outer.y generates an error, even though y is visible in that scope.

Example 1 is more interesting as minigrace is not happy with my definition of y = 3 because it is a redeclaration of an existing name.  However, outer.y is interpreted as y =1, which is consistent with the interpretation as the self of the scope outside the current self.

The point of this (and we could make it even more interesting with inheritance) is that we need to firmly nail down the definition of outer.
Kim






More information about the Grace-core mailing list