unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Yuan Fu <casouri@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Edit a cl-struct by copy, or, slot-value for cl-structs
Date: Fri, 29 Oct 2021 14:46:45 -0700	[thread overview]
Message-ID: <C2FBF0B1-E443-46CA-8626-2A5B468343AF@gmail.com> (raw)
In-Reply-To: <jwvo877lkdo.fsf-monnier+emacs@gnu.org>



> On Oct 29, 2021, at 12:15 PM, Stefan Monnier via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> wrote:
> 
>> (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`.

Ah, silly me!

> 
> 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”)

That’s cool. But my lazy fingers like better to write a single function and use it for everything ;-)

Yuan





  reply	other threads:[~2021-10-29 21:46 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
2021-10-29 21:46   ` Yuan Fu [this message]
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=C2FBF0B1-E443-46CA-8626-2A5B468343AF@gmail.com \
    --to=casouri@gmail.com \
    --cc=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).