aboutsummaryrefslogtreecommitdiff
path: root/guix/records.scm
diff options
context:
space:
mode:
authorMarius Bakke2017-11-19 15:01:00 +0100
committerMarius Bakke2017-11-19 15:01:00 +0100
commit2dd12924cf4a30a96262b6d392fcde58c9f10d4b (patch)
tree3f74f5426ff214a02b8f6652f6516979657a7f98 /guix/records.scm
parent259b4f34ba2eaefeafdb7c9f9eb56ee77f16010c (diff)
parenta93447b89a5b132221072e729d13a3f17391b8c2 (diff)
Merge branch 'master' into core-updates
Diffstat (limited to 'guix/records.scm')
-rw-r--r--guix/records.scm18
1 files changed, 17 insertions, 1 deletions
diff --git a/guix/records.scm b/guix/records.scm
index 7de5fccef..1f00e1660 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -26,7 +26,8 @@
#:export (define-record-type*
alist->record
object->fields
- recutils->alist))
+ recutils->alist
+ match-record))
;;; Commentary:
;;;
@@ -375,4 +376,19 @@ pairs. Stop upon an empty line (after consuming it) or EOF."
(else
(error "unmatched line" line))))))))
+(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 ...))
+ (throw 'wrong-type-arg record)))
+ ((_ record type () body ...)
+ (begin body ...))))
+
;;; records.scm ends here

© 2015 - 2026 Jakob L. Kreuze