[plt-scheme] inheritance of methods

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Oct 2 09:41:44 EDT 2003

At Thu, 2 Oct 2003 13:49:52 +1000, Chris Wright wrote:
> So I can use Foo.double in the subclass  Bar without "declaring the 
> inheritance". I am curious as the the rationale for this design 
> decision 

The declaration is necessary because PLT Scheme classes are first-class
values, the superclass position of the "class" form in an arbitrary

So, the compiler can't statically detect which class will be the
superclass, and therefore can't tell which methods will be provided by
the superclass.

> classs Foo:
>      def __init__(self, x):
>          self.x = x
>      def double(self):
>          return 2 * self.x
> class Bar(Foo):
>      def __init__(self, x):
>          Foo.__init__(self, x)
>      def quadruple(self):
>          return 2 * self.double()

This works fine with PLT Scheme classes, too. Translate `self.double()'
to `(send this double)' instead of `(double)'.

Declaring inheretance is not necessary for `(send this double)'. It's
only necessary for `(double)', which is often easier to read and
generally more efficient.


Posted on the users mailing list.