From: Attila Lendvai <attila@lendvai.name>
To: 60225@debbugs.gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [bug#60225] [PATCH v2 1/2] records: match-record supports specifying a different variable name.
Date: Wed, 21 Dec 2022 23:14:55 -0300 [thread overview]
Message-ID: <20221222021455.18632-1-attila@lendvai.name> (raw)
In-Reply-To: <20221220174018.14433-1-attila@lendvai.name>
An example:
(match-record obj <my-type>
(field1 (field2 custom-var-name) field3)
...)
* guix/records.scm (match-record-inner): Add support for the new syntax.
* tests/records.scm ("match-record, simple"): Add a simple test case for the
new syntax.
---
guix/records.scm | 9 ++++++---
tests/records.scm | 4 ++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/guix/records.scm b/guix/records.scm
index 13463647c8..1f097c7108 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 variable) rest ...) body ...)
+ #'(let-syntax ((field-offset (syntax-rules ()
((_ f)
(lookup-field field 0 f)))))
(let* ((offset (type map-fields field-offset))
- (field (struct-ref record offset)))
+ (variable (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 ...)))))
diff --git a/tests/records.scm b/tests/records.scm
index 8504c8d5a5..b1203dfeb7 100644
--- a/tests/records.scm
+++ b/tests/records.scm
@@ -540,8 +540,8 @@ (define-record-type* <foo> foo make-foo
(first second)
(list first second))
(match-record (foo (first 'a) (second 'b)) <foo>
- (second first)
- (list first second)))))
+ (second (first first/new-var))
+ (list first/new-var second)))))
(test-equal "match-record, unknown field"
'syntax-error
--
2.35.1
next prev parent reply other threads:[~2022-12-22 2:16 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-20 17:40 [bug#60225] [PATCH] records: match-record supports specifying a different variable name Attila Lendvai
2022-12-21 22:15 ` Ludovic Courtès
2022-12-22 2:14 ` Attila Lendvai [this message]
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=20221222021455.18632-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.