help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Edit a cl-struct by copy, or, slot-value for cl-structs


From: Yuan Fu
Subject: Re: Edit a cl-struct by copy, or, slot-value for cl-structs
Date: Fri, 29 Oct 2021 14:46:45 -0700


> 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 via email to

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