GNU bug report logs - #54652
[PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion.

Previous Next

Package: guix-patches;

Reported by: Attila Lendvai <attila <at> lendvai.name>

Date: Thu, 31 Mar 2022 12:49:01 UTC

Severity: normal

Tags: patch

Done: Attila Lendvai <attila <at> lendvai.name>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 54652 in the body.
You can then email your comments to 54652 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix-patches <at> gnu.org:
bug#54652; Package guix-patches. (Thu, 31 Mar 2022 12:49:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Attila Lendvai <attila <at> lendvai.name>:
New bug report received and forwarded. Copy sent to guix-patches <at> gnu.org. (Thu, 31 Mar 2022 12:49:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Attila Lendvai <attila <at> lendvai.name>
To: guix-patches <at> gnu.org
Cc: Attila Lendvai <attila <at> lendvai.name>
Subject: [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD
 expansion.
Date: Thu, 31 Mar 2022 14:46:57 +0200
* guix/records.scm (match-record/fields): New macro.
(match-record): Only check the object type once in the expansion.
---
 guix/records.scm | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/guix/records.scm b/guix/records.scm
index ed94c83dac..e311086d73 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -535,17 +535,25 @@ (define (recutils->alist port)
               (else
                (error "unmatched line" line))))))))
 
+(define-syntax match-record/fields
+  (syntax-rules ()
+    ((_ record type (field fields ...) body ...)
+     (let ((field ((record-accessor type 'field) record)))
+       ;; TODO compute indices and report wrong-field-name errors at
+       ;;      expansion time
+       ;; TODO support thunked and delayed fields
+       (match-record/fields record type (fields ...) body ...)))
+    ((_ record type () body ...)
+     (begin body ...))))
+
 (define-syntax match-record
   (syntax-rules ()
     "Bind each FIELD of a RECORD of the given TYPE to it's FIELD name.
 The current implementation does not support thunked and delayed fields."
     ((_ record type (field fields ...) body ...)
      (if (eq? (struct-vtable record) type)
-         ;; TODO compute indices and report wrong-field-name errors at
-         ;;      expansion time
-         ;; TODO support thunked and delayed fields
-         (let ((field ((record-accessor type 'field) record)))
-           (match-record record type (fields ...) body ...))
+         ;; So that we only test the type once.
+         (match-record/fields record type (field fields ...) body ...)
          (throw 'wrong-type-arg record)))
     ((_ record type () body ...)
      (begin body ...))))
-- 
2.34.0





Information forwarded to guix-patches <at> gnu.org:
bug#54652; Package guix-patches. (Thu, 31 Mar 2022 12:55:02 GMT) Full text and rfc822 format available.

Message #8 received at 54652 <at> debbugs.gnu.org (full text, mbox):

From: Attila Lendvai <attila <at> lendvai.name>
To: 54652 <at> debbugs.gnu.org
Cc: Attila Lendvai <attila <at> lendvai.name>
Subject: [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME)
 forms.
Date: Thu, 31 Mar 2022 14:52:31 +0200
E.g. (match-record obj <type> (field1 (field2 var-name)) ...)

* guix/records.scm (match-record/fields): Implement it.
---

a real world example i was facing: a field name is the same
as an object constructor, and thus shadows it in a
match-record form, unless a different variable name is chosen.

 guix/records.scm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/guix/records.scm b/guix/records.scm
index e311086d73..492ab2aed6 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -537,12 +537,15 @@ (define (recutils->alist port)
 
 (define-syntax match-record/fields
   (syntax-rules ()
-    ((_ record type (field fields ...) body ...)
-     (let ((field ((record-accessor type 'field) record)))
+    ((_ record type ((field-name variable-name) fields ...) body ...)
+     (let ((variable-name ((record-accessor type 'field-name) record)))
        ;; TODO compute indices and report wrong-field-name errors at
        ;;      expansion time
        ;; TODO support thunked and delayed fields
        (match-record/fields record type (fields ...) body ...)))
+    ((_ record type (field fields ...) body ...)
+     ;; Channel it back into the canonical form above.
+     (match-record/fields record type ((field field) fields ...) body ...))
     ((_ record type () body ...)
      (begin body ...))))
 
-- 
2.34.0





Information forwarded to guix-patches <at> gnu.org:
bug#54652; Package guix-patches. (Thu, 30 Jun 2022 13:57:01 GMT) Full text and rfc822 format available.

Message #11 received at 54652 <at> debbugs.gnu.org (full text, mbox):

From: Attila Lendvai <attila <at> lendvai.name>
To: "54652 <at> debbugs.gnu.org" <54652 <at> debbugs.gnu.org>
Subject: (No Subject)
Date: Thu, 30 Jun 2022 13:56:13 +0000
one questionable thing: if fields is the empty list, then it skips entirely the runtime assert that checks the record type.




Reply sent to Attila Lendvai <attila <at> lendvai.name>:
You have taken responsibility. (Sun, 20 Nov 2022 14:19:01 GMT) Full text and rfc822 format available.

Notification sent to Attila Lendvai <attila <at> lendvai.name>:
bug acknowledged by developer. (Sun, 20 Nov 2022 14:19:02 GMT) Full text and rfc822 format available.

Message #16 received at 54652-close <at> debbugs.gnu.org (full text, mbox):

From: Attila Lendvai <attila <at> lendvai.name>
To: "54652-close <at> debbugs.gnu.org" <54652-close <at> debbugs.gnu.org>
Subject: (No Subject)
Date: Sun, 20 Nov 2022 14:18:11 +0000
closing, it was superseded by #59390

https://issues.guix.gnu.org/59390

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Personal dishonesty is not needed to produce a dishonest business plan or research proposal. Wishful thinking suffices.”
	— John McCarthy (1927–2011), father of Lisp





bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 19 Dec 2022 12:24:10 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 182 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.