[Grace-core] "Object Algebras" in Grace
James Noble
kjx at ecs.vuw.ac.nz
Fri Jul 13 04:37:52 PDT 2012
> I am sorry to get back to you on this so late; but I have been busy for the past few weeks.
> However I've been slowly thinking about nesting, family polymorphism and object algebras.
Good - no problem, we've been busy too, and in my case still are.
Yes I'm still planning on sending (various) versions of Grace approaches for your web page.
> I've come up with an encoding that uses object algebras to achieve the late binding typical
> of family polymorphism approaches like virtual classes. The encoding uses Java's nested
> classes. The code goes in annexe.
OK, I'll have to study it...
> I'd like to see how this encoding compares to existing virtual classes/nested inheritance approaches.
Something we're looking at in Grace, trying a few examples, is the virtual superclasses
one finds e.g. in Newspeak and (I think) in other OOLs:
class BaseFamily.new {
class FirstClass.new { method m { "BaseFirst" } }
class SecondClass.new {
inherits FirstClass.new
method m { super.m ++ " BaseSecond" } }
}
class ExtendedFamily.new is overriding {
inherits BaseFamily.new
class FirstClass.new is overriding {
inherits super.FirstClass.new
method m { super.m ++ " ExtendedFirst" }
}
}
print (ExtendedFamily.new.SecondClass.new.m)
what we want to see is "BaseFirst ExtendedFirst BaseSecond" -
i.e. SecondClass in the ExtendedFamily inherits from FirstClass
*in the ExtendedFamily* - even though the only declaration is
in the BaseFamily where SecondClass inherits from FirstClass.
The point is that superclass is virtual - or dynamic as I think Gilad would put it -
it is resolved at runtime, at the time an instance of ExtendedFamily.SecondClass
is created.
I don't see how object algebrae allow this kind of inheritance and extension,
especially not in Java, where classes are aggressively not virtual, and
inner classes are never overridden. But perhaps I just haven't looked at
your example hard enough?
> I think this may be worthwhile exploring a bit more and perhaps writing something up. Do let me know of comments, questions or limitations.
well I'm keen. I may not have much time but I'm keen.
James
PS - due to bugs, the code above doesn't actually work in our prototype
minigrace implementation http://homepages.ecs.vuw.ac.nz/~mwh/minigrace/js/
This code below is roughly similar, but doesn't trigger those bugs.
class BaseFamily.new {
method FirstClass_new { object { method m { "BaseFirst" } } }
method SecondClass_new {
def daddy = FirstClass_new
return object {
inherits daddy
method m { super.m ++ " BaseSecond" } }
} }
class ExtendedFamily.new {
inherits BaseFamily.new
method FirstClass_new {
return object {
inherits super.FirstClass_new
method m { super.m ++ " ExtendedFirst" }
} }
}
print (ExtendedFamily.new.SecondClass_new.m)
More information about the Grace-core
mailing list