[Grace-core] Super-Outer-Objects: What does your language (gBeta/Newspeak/Scala/Java…) do with this? What should Grace do?

James Noble kjx at ecs.vuw.ac.nz
Mon Nov 19 02:26:25 PST 2012


Hi all

late last week we had a discussion about "super-outer-objects":
what happens if a method is inherited from a super object 
(or superclass) but the superclass then involves a send that is 
bound to some outer, nested definition?

Hopefully the code below is short enough to be clear: 
object C inherits "foo" from B, and overrides "pathological";
but B's foo method calls resolves to an "outer" definition
of "pathological" in A.

If this were Self, and nesting was just multiple inheritance,
both calls to "C" would resolve to "C-pathological". 

What do other languages do?     What should Grace do?  


#pragma DefaultVisibility=public

def A = object {
  method pathological {print "A-pathological"}  
  def B = object {
    method foo {pathological}
  }
}
def C = object { 
  inherits A.B
  method pathological {print "C-pathological"}
}

A.pathological
A.B.foo
C.pathological
C.foo

cheers

James 

PS minigrace C & JS backends make C.foo call "A-pathological";
the minigrace repl currently crashes...
the Java code below also makes C.foo call "A-pathological".

class A {
    void pathological() {System.out.println("A-pathological");}
    class B {
	void foo() {pathological();}
    }
    class C extends A.B {
	void pathological() {System.out.println("C-pathological");}
    }
    public static void main(String[] args) {
	new A().pathological();
	new A().new B().foo();
	new A().new C().pathological();
	new A().new C().foo();
	System.out.println("Done!");
    }
}



More information about the Grace-core mailing list