Re: Polymorphism in eieio

Sylvain Salvati <[email protected]> Thu, 20 Oct 2016 08:27:05 +0200
Newsgroups gmane.emacs.eieio
Message-ID <[email protected]>
I found my mistake. As a new elisp programmer I still get confused with
quotation...

Best,

Sylvain.


Sylvain Salvati writes:

> 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