On Sun, Mar 16, 2003 at 10:08:41PM -0500, Chris Dutton wrote:
> On Sunday, March 16, 2003, at 05:09 PM, David Storrs wrote:
> 
> > ==QUESTION
> > - Page 8 says "In some languages, all methods are multimethods."  I
> > believe that Java is one of these.  Is that right and what are some
> > others?  (This is really just curiousity.)
> > ==/
> 
> Doesn't C++ work this way?  Also I believe Pike allows overloading of 
> methods by default.

Nope.  C++ will only dispatch on the type of the first argument (the
implicitly-passed argument which becomes the "this" pointer).


> > ==QUESTION
> > - Given the following code, what is called by $ride.current_speed()?
> >
> >     class Vehicle {
> >       my $speed;
> >       method current_speed() { return $speed; }
> >       method set_speed($n) { $speed = $n; }
> >     }
> >
> >     class Car {
> >       submethod current_speed() {
> >          print SUPER.current_speed();
> >          return SUPER.current_speed();
> >       }
> >     }
> >
> >     class A6 {  }
> >
> >     my $ride = new A6;            # Perl with German engineering???
> >     $ride.set_speed(60);          # Calls Vehicle.set_speed()
> >     print $ride.current_speed();  # Calls what?
> 
> Unless this is more complicated than I think, Car's current_speed() is 
> called.

I should have included the relevant quote (which I can't find right
now).  This was a question specifically related to submethods.  If I
understand correctly, submethods allow you to declare a method in a
base class, and override it in a derived class such that the
overidden submethod is not visible from classes derived from there on
down.  So, if I'm right about this, calling $ride.current_speed() will
actually call Vehicle's method, because Car's is not visible (being a
submethod).  


> That said, a minor nitpick is that you'd want something more like
> 
> class Vehicle { ... }
> class Car is Vehicle { ... }
> class A6 is Car { ... }

D'oh!  Yes, of course.  


--Dks

Reply via email to