all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Attila Lendvai <attila@lendvai.name>
To: 60225@debbugs.gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [bug#60225] [PATCH] records: match-record supports specifying a different variable name.
Date: Tue, 20 Dec 2022 14:40:19 -0300	[thread overview]
Message-ID: <20221220174018.14433-1-attila@lendvai.name> (raw)

An example:

(match-record obj <my-type>
  (field1 (field2 custom-var-name) field3)
  ...)
---
 guix/records.scm | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/guix/records.scm b/guix/records.scm
index 13463647c8..0b2487a156 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -592,13 +592,16 @@ (define-syntax lookup-field
 (define-syntax match-record-inner
   (lambda (s)
     (syntax-case s ()
-      ((_ record type (field rest ...) body ...)
-       #`(let-syntax ((field-offset (syntax-rules ()
+      ((_ record type ((field-name variable-name) rest ...) body ...)
+       #'(let-syntax ((field-offset (syntax-rules ()
 			              ((_ f)
-                                       (lookup-field field 0 f)))))
+                                       (lookup-field field-name 0 f)))))
            (let* ((offset (type map-fields field-offset))
-                  (field  (struct-ref record offset)))
+                  (variable-name (struct-ref record offset)))
              (match-record-inner record type (rest ...) body ...))))
+      ((_ record type (field rest ...) body ...)
+       ;; Redirect to the canonical form above.
+       #'(match-record-inner record type ((field field) rest ...) body ...))
       ((_ record type () body ...)
        #'(begin body ...)))))
 
-- 
2.35.1





             reply	other threads:[~2022-12-20 18:20 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-20 17:40 Attila Lendvai [this message]
2022-12-21 22:15 ` [bug#60225] [PATCH] records: match-record supports specifying a different variable name Ludovic Courtès
2022-12-22  2:14 ` [bug#60225] [PATCH v2 1/2] " Attila Lendvai
2022-12-22  2:14   ` [bug#60225] [PATCH v2 2/2] tests: records: Add a failing test for match-record Attila Lendvai
2022-12-27 22:53     ` [bug#60225] [PATCH] records: match-record supports specifying a different variable name Ludovic Courtès
2022-12-27 22:49   ` bug#60225: " Ludovic Courtès

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=20221220174018.14433-1-attila@lendvai.name \
    --to=attila@lendvai.name \
    --cc=60225@debbugs.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/guix.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.