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: Thu, 08 Apr 2021 00:44:15 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> 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.

I'd welcome patches to make them work with cl-structs.
For `slot-value` this should be quite easy.  For `make-instance` there
are some choices to be made about the semantics we want to offer, so
maybe it's not harder to implement but it requires more thought.

> 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.

Note you can also use things like:

    (cl-defstruct (my-foo
                   (:constructor nil)
                   (:constructor my-constructor-name
                     (slot1 slot2 &aux (_ (when (> slot1 slot2))
                                            (error "blabla")))))
      slot1 slot2)

which might cover some of that ground as well.
I find those `&aux` thingies hideous, tho, so don't take this as
a recommendation.

AFAIK the only thing really missing is the ability to call-next-method
to the parent's constructor, so the children's constructor either have
to duplicate the work of their parent, or they have to manually call
some ad-hoc function that encapsulates the work of the
parent's constructor.
I can imagine cases where it increases annoyingly the coupling between
the parent and the child types, tho in my experience, this coupling is
pretty much always tight for other reasons anyway, so it's never been
a problem for me.


        Stefan




reply via email to

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