[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EIEIO default constructor function
From: |
Mario Lang |
Subject: |
Re: EIEIO default constructor function |
Date: |
Thu, 08 Apr 2021 05:37:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.1.50 (gnu/linux) |
Hi Stefan.
Thanks a lot. :include is just what I was looking for.
And while `make-instance' and `slot-value' are convenient, I guess I can
work around not having them. Having `initialize-instance' would
also have been convenient, but since I apparently only needed an :after
method I ended up using the :constructor option to rename the generated
constructor to indicate it is internal.
So it appears I can actually do without `defclass' and friends.
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 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
--
CYa,
⡍⠁⠗⠊⠕