Reading myself in Lisp, currently on this page ( http://landoflisp.com ), I found the following expression in the second and last paragraph on the page that appears when you click the CLOS GUILD link:
It is important to note that in order to find out which mixing method is invoked in a given situation, CLOS must take into account both objects passed to this method. It sends a concrete implementation of a method based on the types of several objects. This is a feature that is not available in traditional object-oriented languages ββsuch as Java or C ++.
Here is an example of Lisp -code:
(defclass color () ()) (defclass red (color) ()) (defclass blue (color) ()) (defclass yellow (color) ()) (defmethod mix ((c1 color) (c2 color)) "I don't know what color that makes") (defmethod mix ((c1 blue) (c2 yellow)) "you made green!") (defmethod mix ((c1 yellow) (c2 red)) "you made orange!")
No, I think the last sentence is wrong. I really can do just that with the following Java code:
public class Main { public static void main(String[] args) { mix(new Red(), new Blue()); mix(new Yellow(), new Red()); } public static void mix(Color c1, Color c2) { System.out.println("I don't know what color that makes"); } public static void mix(Blue c1, Yellow c2) { System.out.println("you made green!"); } public static void mix(Yellow c1, Red c2) { System.out.println("you made orange!"); } } class Color {} class Red extends Color {} class Blue extends Color {} class Yellow extends Color {}
which gives me the same result when I run it:
I don't know what color that makes you made orange!
So my question is: is this sentence on this page really wrong and possible in Java / C ++? If so, maybe this was not possible in an older version of Java? (Although I doubt very much that since the book is only 5 years old) If not, what did I forget to consider in my example?
java class lisp multiple-dispatch clos
Mathias bader
source share