From 4cd529362108086eeec25d4d465261415cff45b3 Mon Sep 17 00:00:00 2001 From: "(unmatched-parenthesis ew syntax" Date: Fri, 28 Apr 2023 20:19:05 +0100 Subject: 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 --- guix/records.scm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'guix/records.scm') 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 -- cgit v1.2.3