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

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).