mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-24 21:38:07 -05:00
guix: records: Add match-record.
* guix/records.scm: New syntax-rule. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
50c229caf9
commit
6692d8454a
1 changed files with 17 additions and 1 deletions
|
@ -26,7 +26,8 @@ (define-module (guix records)
|
|||
#:export (define-record-type*
|
||||
alist->record
|
||||
object->fields
|
||||
recutils->alist))
|
||||
recutils->alist
|
||||
match-record))
|
||||
|
||||
;;; Commentary:
|
||||
;;;
|
||||
|
@ -375,4 +376,19 @@ (define (recutils->alist port)
|
|||
(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
|
||||
|
|
Loading…
Reference in a new issue