[Grace-core] The no shadowing rule

Kim Bruce kim at cs.pomona.edu
Tue Sep 23 22:47:57 PDT 2014


Yes, I suppose this is a case where the translation looks different from the original;

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

can be translated to 

def test = object {
     method with(x: Number) {
          object {
               def x: Number = 2
               print(x)
          }
     }
}

Somehow I don't really want to explain that to novices, which I guess implies I want the same answer to both -- i.e., both should be illegal (though at this point I'd be happy with a warning).

Kim



On Sep 23, 2014, at 9:48 PM, 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




More information about the Grace-core mailing list