[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#54652] [PATCH 2/2] guix: MATCH-RECORD supports (FIELD-NAME VARIABLE
From: |
Attila Lendvai |
Subject: |
[bug#54652] [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