Python syntax in Lisp and Scheme

Pascal Costanza costanza at web.de
Wed Oct 8 17:50:41 EDT 2003


Christopher C. Stacy wrote:

> JAVA has multi-methods with non-congruent arglist.
> (It doesn't have multiple inheritence, but that doesn't 
> matter to dynamic type dispatching, except maybe in how 
> you implement searching your handler tables.)  In JAVA, 
> the correspondance of the "signature" of the function call
> and the method definition are what's important;
> and there are no restricting "generic functions".
> 
> public class RandomAccessFile extends Object,implements DataOutput {
>   public void write(byte[] b) throws IOException;
>   public void write(byte[] b, int off, int len) throws IOException;
>   ...
> }

Maybe this is just a terminological issue, but in my book these are not 
multi-methods. In Java, methods with the same name but different 
signatures are selected at compile time, and this is rather like having 
the parameter types as part of the method name.

This can lead to subtle bugs. Here is an example in Java:

public class test {

     static void m(Object o) {
       System.out.println("m/Object");
     }

     static void m(String s) {
       System.out.println("m/String");
     }

     static void n(Object o) {
       m(o);
     }

     public static void main(String[] args) {
       n("test");
     }

}

This prints "m/Object", instead of "m/String" as you might expect. (This 
is one of the reasons why the Visitor pattern is relatively tedious to 
implement in Java.)


Pascal





More information about the Python-list mailing list