emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EIEIO default constructor function


From: Stefan Monnier
Subject: Re: EIEIO default constructor function
Date: Sun, 04 Apr 2021 10:12:48 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Maybe I was using sloppy terminology, but as far as I can see, `cl-defstruct'
> can not have a parent relationship, so what I call inheritance-based
> dispatch isn't really possible with cl-defstruct?
>
> (defclass foo () ())
> (cl-defmethod val ((foo foo)) 0)
> (defclass bar (foo) ())
> (cl-defmethod val ((bar bar)) 1)

    (cl-defstruct (my-foo)
      slot1)
    (cl-defmethod my-val ((x my-foo)) (my-foo-slot1 x))
    (cl-defstruct (my-bar
                   (:include my-foo))
      slot2)
    (cl-defmethod my-val ((x my-bar))
      (+ (my-bar-slot2 x) (cl-call-next-method)))

     (my-val (make-my-bar :slot1 4 :slot2 5))
     ==> 9


-- Stefan
      




reply via email to

[Prev in Thread] Current Thread [Next in Thread]