Polymorphism in eieio
Sylvain Salvati <[email protected]> Wed, 19 Oct 2016 19:13:57 +0200
| Newsgroups | gmane.emacs.eieio |
|---|---|
| Message-ID | <[email protected]> |
Dear list,
I ma trying to use eieio to write code in elisp. But I am stuck with a
problem related to polymorphism. Here is a simple example showing my
problem
(defclass a()
((a :initarg :a
:initform 0))
"class a")
(defclass b()
((b :initarg :b
:initform 0))
"class b")
(defmethod nb ((xa a))
(oref xa :a))
(defmethod nb ((xb b))
(oref xb :b))
(setq xa (a))
(setq xb (b))
(nb xa) ;;yields 0 as expected
(nb xb) ;;also yields 0
(mapcar 'nb '(xa xb)) ;; yields cl-no-applicable-method (nb xa)
I create two classes a and b and they both have a method nb. When I have
a list made of objects that can be either a's or b's I would expect to
be able to map the method nb on the list, but this fails. Is there a
workaround this problem.
Thanks,
Sylvain.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot