all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eduardo Ochs <eduardoochs@gmail.com>
To: help-gnu-emacs <help-gnu-emacs@gnu.org>
Subject: Re: How do I find the names of the fields of a struct?
Date: Tue, 8 Jun 2021 01:23:33 -0300	[thread overview]
Message-ID: <CADs++6jkVF9=hdkmBZa4uWmjLJ0kovrivys+OhhULFGTHCxaFQ@mail.gmail.com> (raw)
In-Reply-To: <CADs++6gDDNVYr+OmLPa3CWpN639zEpPW+Nz3qyaCT2fvXdJXRA@mail.gmail.com>

On Mon, 7 Jun 2021 at 21:38, Eduardo Ochs <eduardoochs@gmail.com> wrote:
>
> Hi list,
>
> if I define a "mystruct" object with
>
>   (cl-defstruct mystruct fieldA fieldB fieldC)
>   (setq mys (make-mystruct :fieldA 22 :fieldC "44"))
>
> and inspect it in the obvious way I get this:
>
>   mys
>     ;; -> #s(mystruct 22 nil "44")
>   (type-of mys)
>     ;; -> mystruct
>   (recordp mys)
>     ;; -> t
>   (aref mys 0)
>     ;; -> mystruct
>   (aref mys 1)
>     ;; -> 22
>   (aref mys 2)
>     ;; -> nil
>   (aref mys 3)
>     ;; -> "44"
>
> Is there a way to recover the names of the fields of a structure that
> has been already defined? I'd like to be able to write a function
> `ee-struct-to-string' - meant to be just a very primitive hacking
> tool, as simple as possible, with no error checking at all - that
> would work like this: this sexp
>
>   (ee-struct-to-string mys)
>
> would return this multi-line string:
>
>   0 type-name-field "mystruct"
>   1 fieldA 22
>   2 fieldB nil
>   3 fieldC "44"
>
> Finding the field name associated to each position in the record is
> the tricky part...
>
>   Thanks in advance!
>     Eduardo Ochs
>     http://angg.twu.net/#eev


Problem solved!
The code is here:

  http://angg.twu.net/eev-current/eev-blinks.el

Look for "defun ee-struct-to-string".

  [[]] =),
    http://angg.twu.net/#eev



  reply	other threads:[~2021-06-08  4:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-08  0:38 How do I find the names of the fields of a struct? Eduardo Ochs
2021-06-08  4:23 ` Eduardo Ochs [this message]
2021-06-08 16:21 ` Stefan Monnier via Users list for the GNU Emacs text editor

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

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

  git send-email \
    --in-reply-to='CADs++6jkVF9=hdkmBZa4uWmjLJ0kovrivys+OhhULFGTHCxaFQ@mail.gmail.com' \
    --to=eduardoochs@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.