This is the mail archive of the guile@sourceware.cygnus.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Philosophy and object systems (was Re: goops/guile doc)


Per Bothner <per@bothner.com> writes:

> Jost Boekemeier <jostobfe@linux.zrz.TU-Berlin.DE> writes:
> 
> > See Meyer's discussion about simulating genericity with inherintance
> > and vice versa.  
> 
> IIRC by "genericity" Meyer refers to parametric polymorphism, not
> generic functions.  

Where is the difference?  Even fortran has generic functions (parametric
polymorphism):  You can link your program with different libraries.

Here is his swap example:

procedure swap (x, y) is
   t: local;
begin
   t := x; x := y; y := t;
end


The only difference between multiple dispatch and polymorphism as used
in java for example is that the generic *belongs* to a specific class
and that the first parameter (self) is therefore always implicit.
That means that the concrete (function, method -- how do you call it?)
can only change (the content of) self, but not (the content of) the
other arguments.

It is true that Java doesn't dispatch on the object's dynamic type but
that's a different story.  I would call it a bug:

class A {
  public void ID() {Out.bla.println("A");
}

class B extends A {
  public void ID() {Out.bla.println("B");
}

class CLIENT {
   static A convert (A a) { return a; };

   static void main(String s[]) {
      A a = new A();
      B b = a;
//    B b = (B) convert(a); // explicit type guard needed! Huaaa!

      b.ID();  // prints "A" (sic!)
      a.ID();  // prints "A"
}

Java sucks... :)

Jost

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]