unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Edit a cl-struct by copy, or, slot-value for cl-structs
Date: Fri, 29 Oct 2021 15:15:45 -0400	[thread overview]
Message-ID: <jwvo877lkdo.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 06C2AE7C-C3E9-4E34-9394-B431173639E9@gmail.com

> (mapcar #'cl--slot-descriptor-name
>         (cl--struct-class-slots (get (type-of obj) 'cl--class)))
>
> But I can’t get any further as I can’t find any generic getter and
>  setter for cl-struct’s. Something like slot-value. So close!

The position of the slot descriptor in `cl--struct-class-slots` mirrors the
position of the slot in the actual objet, so you just need `aref/aset`.

It would also make a lot of sense to replace/extend the useless
`:copier` thingy of `cl-defstruct` with something like the
`:constructor`, so you could say

    (cl-defstruct (my-foo
                   (:copier my-foo-with)
                   (:copier my-foo-with-a (b a)))
      a b c)

and then use (my-foo-with foo :c 42) and (my-foo-with-a foo 153 "42")


        Stefan




  parent reply	other threads:[~2021-10-29 19:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-29 18:27 Edit a cl-struct by copy, or, slot-value for cl-structs Yuan Fu
2021-10-29 18:43 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-29 21:44   ` Yuan Fu
2021-10-29 19:15 ` Stefan Monnier via Users list for the GNU Emacs text editor [this message]
2021-10-29 21:46   ` Yuan Fu
2021-10-31 18:52     ` Stefan Monnier
2021-10-29 21:37 ` Michael Heerdegen
2021-10-29 22:02   ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-10-29 23:14     ` Michael Heerdegen

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=jwvo877lkdo.fsf-monnier+emacs@gnu.org \
    --to=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
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).