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: Stefan Monnier
Subject: Re: Edit a cl-struct by copy, or, slot-value for cl-structs
Date: Fri, 29 Oct 2021 15:15:45 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

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




reply via email to

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