unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
* [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion.
@ 2022-03-31 12:46 Attila Lendvai
  2022-03-31 12:52 ` [bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms Attila Lendvai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Attila Lendvai @ 2022-03-31 12:46 UTC (permalink / raw)
  To: 54652; +Cc: Attila Lendvai

* 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





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms.
  2022-03-31 12:46 [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion Attila Lendvai
@ 2022-03-31 12:52 ` Attila Lendvai
  2022-06-30 13:56 ` [bug#54652] (No Subject) Attila Lendvai
  2022-11-20 14:18 ` bug#54652: " Attila Lendvai
  2 siblings, 0 replies; 4+ messages in thread
From: Attila Lendvai @ 2022-03-31 12:52 UTC (permalink / raw)
  To: 54652; +Cc: Attila Lendvai

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





^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [bug#54652] (No Subject)
  2022-03-31 12:46 [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion Attila Lendvai
  2022-03-31 12:52 ` [bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms Attila Lendvai
@ 2022-06-30 13:56 ` Attila Lendvai
  2022-11-20 14:18 ` bug#54652: " Attila Lendvai
  2 siblings, 0 replies; 4+ messages in thread
From: Attila Lendvai @ 2022-06-30 13:56 UTC (permalink / raw)
  To: 54652@debbugs.gnu.org

one questionable thing: if fields is the empty list, then it skips entirely the runtime assert that checks the record type.




^ permalink raw reply	[flat|nested] 4+ messages in thread

* bug#54652: (No Subject)
  2022-03-31 12:46 [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion Attila Lendvai
  2022-03-31 12:52 ` [bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms Attila Lendvai
  2022-06-30 13:56 ` [bug#54652] (No Subject) Attila Lendvai
@ 2022-11-20 14:18 ` Attila Lendvai
  2 siblings, 0 replies; 4+ messages in thread
From: Attila Lendvai @ 2022-11-20 14:18 UTC (permalink / raw)
  To: 54652-close@debbugs.gnu.org

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





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-20 14:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-31 12:46 [bug#54652] [PATCH 1/2] guix: Only check the object type once in the MATCH-RECORD expansion Attila Lendvai
2022-03-31 12:52 ` [bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms Attila Lendvai
2022-06-30 13:56 ` [bug#54652] (No Subject) Attila Lendvai
2022-11-20 14:18 ` bug#54652: " Attila Lendvai

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).