[plt-scheme] inheritance of methods

From: Chris Wright (caw at cs.mu.oz.au)
Date: Wed Oct 1 23:49:52 EDT 2003

Having run the "stack" demo in the docs (MzLib Chapter 4 class.ss), and 
read this:

While all of named-stack%, double-stack%, and safe-stack% inherit the 
push! method of stack%, it is declared with inherit only in 
double-stack%; new declarations in named-stack% and safe-stack% do not 
need to refer to push!, so the inheritance does not need to be 
declared. Similarly, only safe-stack% needs to declare (inherit none?).

I think I have a question :)

in AnotherLanguageButQuiteNice, I'd write

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()

 >>> f = Foo(2)
 >>> print f.double()
4
 >>> b = Bar(2)
 >>> print b.double()
4
 >>> print b.quadruple()
8


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 (but not knowledgeable enough to be critical :). As you all 
know, some scheme object models (STk, the examples in Teach Yourself 
Scheme in Fixnum Days etc etc) have a syntax more reminiscent of the 
Python examples above.

Just curious

Chris


Dr. Chris Wright
Medical Director
Intensive Care Unit
Monash Medical Centre, Clayton VIC



Posted on the users mailing list.