aboutsummaryrefslogtreecommitdiff
path: root/guix/records.scm
diff options
context:
space:
mode:
author(unmatched-parenthesis ew syntax <paren@disroot.org>2023-04-28 20:19:05 +0100
committerJosselin Poiret <dev@jpoiret.xyz>2023-06-04 10:59:25 +0200
commit4cd529362108086eeec25d4d465261415cff45b3 (patch)
treecbb0b3e462513d52260f8be7bcc8f2176fbf3840 /guix/records.scm
parente6dc1d399663b9fab30ded8bcb716a5b1dbf8743 (diff)
downloadguix-4cd529362108086eeec25d4d465261415cff45b3.tar
guix-4cd529362108086eeec25d4d465261415cff45b3.tar.gz
records: Add MATCH-RECORD-LAMBDA.
* guix/records.scm (match-record-lambda): New syntax. * tests/records.scm ("match-record-lambda"): New test. Signed-off-by: Josselin Poiret <dev@jpoiret.xyz>
Diffstat (limited to 'guix/records.scm')
-rw-r--r--guix/records.scm14
1 files changed, 13 insertions, 1 deletions
diff --git a/guix/records.scm b/guix/records.scm
index cfa46f0d80..2a88cb4b3c 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -31,7 +31,8 @@
alist->record
object->fields
recutils->alist
- match-record))
+ match-record
+ match-record-lambda))
;;; Commentary:
;;;
@@ -640,4 +641,15 @@ an unknown field is queried."
(match-record-inner record type (fields ...) body ...)
(throw 'wrong-type-arg record)))))
+(define-syntax match-record-lambda
+ (syntax-rules ()
+ "Return a procedure accepting a single record of the given TYPE for which each
+FIELD will be bound to its FIELD name within the returned procedure. A syntax error
+is raised if an unknown field is queried."
+ ((_ type (field ...) body ...)
+ (lambda (record)
+ (if (eq? (struct-vtable record) type)
+ (match-record-inner record type (field ...) body ...)
+ (throw 'wrong-type-arg record))))))
+
;;; records.scm ends here