diff mbox series

[bug#54652,2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE-NAME) forms.

Message ID 20220331125230.4388-2-attila@lendvai.name
State New
Headers show
Series [bug#54652,1/2] guix: Only check the object type once in the MATCH-RECORD expansion. | expand

Commit Message

Attila Lendvai March 31, 2022, 12:52 p.m. UTC
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 mbox series

Patch

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