[Grace-core] Meaning of outer

Michael Homer mwh at ecs.vuw.ac.nz
Mon Aug 5 18:24:59 PDT 2013


On Tue, Aug 6, 2013 at 12:56 PM, Kim Bruce <kim at cs.pomona.edu> wrote:
> 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?
By this definition it is a static error, no such method y.
> 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?
Same as above.
> 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:
Still no change.
> 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.
Andrew is in favour of interpreting it as a concrete object reference.
I don't know what anyone else wants. Minigrace implements outer as you
described, and more or less as Andrew wants it, but it wasn't intended
to be something you'd ever write, only something that was generated
internally to make compilation easier.
-Michael



More information about the Grace-core mailing list