unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Mario Lang <mlang@blind.guru>
Cc: emacs-devel@gnu.org
Subject: Re: EIEIO default constructor function
Date: Thu, 08 Apr 2021 00:44:15 -0400	[thread overview]
Message-ID: <jwva6q975t7.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <87lf9t5twc.fsf@blind.guru> (Mario Lang's message of "Thu, 08 Apr 2021 05:37:07 +0200")

> 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	other threads:[~2021-04-08  4:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-03  3:50 EIEIO default constructor function Mario Lang
2021-04-03 13:48 ` Stefan Monnier
2021-04-04  2:42   ` Mario Lang
2021-04-04  3:10     ` Stefan Monnier
2021-04-04  8:39       ` Mario Lang
2021-04-04 14:12         ` Stefan Monnier
2021-04-08  3:37           ` Mario Lang
2021-04-08  4:44             ` Stefan Monnier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwva6q975t7.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=mlang@blind.guru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).