Imagine that we have a base class number that has implemented a integer and floats, but not complex numbers and that we would like to extend it to also support complex numbers:
;; this is from the number implementation
(defgeneric add ((a number) (b number))
(:documentation "Adds two numbers together."))
(defmethod number:add ((a my-complex-number) (b my-complex-number))
...)
(defmethod number:add ((a my-complex-number) (b number))
...)
(defmethod number:add ((b number) (a my-complex-number))
...)
The body of the two last would be exatly the same and yet they are needed in order to do (reduce #'add list-of-numbers) since the number implementation doesn't know how to add complex numbers.
It seems to me like some sort of syntax to indicate the (or some) arguments can occur in any order. In CL I'm sure this can be fixed by making a macro that generates all the versions, but this isn't just a CL problem.
Imagine you have a number tower with an add method in Java and you extend it with a MyComplexNumber class with the same add method. How does noe make sure floatObject.add(complexObject) would work?
ComplexNumber know of the Number class hiarchy but not vice versa. Thus by importing ComplexNumber package it would be nice to "infect" the other classes add methods without changing their code.
Is there a language out there that has abstraction to solve this?