[Grace-core] The no shadowing rule

Andrew P. Black black at cs.pdx.edu
Tue Sep 23 22:53:51 PDT 2014


On 23 Sep 2014, at 21:48, Michael Homer <mwh at ecs.vuw.ac.nz> wrote:

> On Wed, Sep 24, 2014 at 4:41 PM, Kim Bruce <kim at cs.pomona.edu> wrote:
>> The difference between the two is that in programs 1 & 2 the x which is a
>> parameter is in the same scope as the def x (respectively, method x) inside
>> the class.
> No it isn't. Parameter declarations are scoped to the method, and
> field declarations are scoped to the object.
> -Michael


I believe that what Michael is saying is that, in minigrace, in 

Program 1:

class test.with(x:Number) {
      def x: Number = 2
      print(x)
}

parameter x is in an outer scope (that of the method with), while def x is in an inner scope (that of the implicit object constructor).   Which is exactly why I was having difficulty distinguishing this from program 3.

That doesn’t mean that the scopes _ought_ to be this way.   The spec is not very enlightening on this point.  It does say clearly (§7.1) that "Object literals are lexically scoped inside their containing method, or block”, and it almost but not quite defines a class by expansion.  We need to be clearer about this. 

	Andrew






More information about the Grace-core mailing list