[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
02/10: records: Separate default-value handling.
From: |
Ludovic Courtès |
Subject: |
02/10: records: Separate default-value handling. |
Date: |
Thu, 11 Jun 2015 21:33:40 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit b9c8647337762983ac046aec66328ad0efd2f276
Author: Ludovic Courtès <address@hidden>
Date: Thu Jun 11 21:49:02 2015 +0200
records: Separate default-value handling.
* guix/records.scm (make-syntactic-constructor)[default-values]: New
variable.
[field-default-value]: New procedure.
Use them.
---
guix/records.scm | 23 +++++++++++++----------
1 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/guix/records.scm b/guix/records.scm
index 2378969..f66fda8 100644
--- a/guix/records.scm
+++ b/guix/records.scm
@@ -91,6 +91,16 @@ fields, and DELAYED is the list of identifiers of delayed
fields."
#`(delay #,value))
(else value)))
+ (define default-values
+ ;; List of symbol/value tuples.
+ (map (match-lambda
+ ((f v)
+ (list (syntax->datum f) v)))
+ #'defaults))
+
+ (define (field-default-value f)
+ (car (assoc-ref default-values (syntax->datum f))))
+
(define (field-bindings field+value)
;; Return field to value bindings, for use in 'let*' below.
(map (lambda (field+value)
@@ -106,22 +116,15 @@ fields, and DELAYED is the list of identifiers of delayed
fields."
#,(record-inheritance #'orig-record
#'((field value) (... ...)))))
((_ (field value) (... ...))
- (let ((fields (map syntax->datum #'(field (... ...))))
- (dflt (map (match-lambda
- ((f v)
- (list (syntax->datum f) v)))
- #'defaults)))
-
+ (let ((fields (map syntax->datum #'(field (... ...)))))
(define (field-value f)
(or (and=> (find (lambda (x)
(eq? f (car (syntax->datum x))))
#'((field value) (... ...)))
car)
- (let ((value
- (car (assoc-ref dflt (syntax->datum f)))))
- (wrap-field-value f value))))
+ (wrap-field-value f (field-default-value f))))
- (let ((fields (append fields (map car dflt))))
+ (let ((fields (append fields (map car default-values))))
(cond ((lset= eq? fields '(expected ...))
#`(let* #,(field-bindings
#'((field value) (... ...)))
- branch master updated (b45ce07 -> 6c35641), Ludovic Courtès, 2015/06/11
- 02/10: records: Separate default-value handling.,
Ludovic Courtès <=
- 04/10: records: "options" → "properties"., Ludovic Courtès, 2015/06/11
- 03/10: records: Factorize field property predicates., Ludovic Courtès, 2015/06/11
- 01/10: records: Replace 'eval-when' with a proper 'define-syntax'., Ludovic Courtès, 2015/06/11
- 05/10: records: Add support for 'innate' fields., Ludovic Courtès, 2015/06/11
- 07/10: gnu: guix: Update snapshot., Ludovic Courtès, 2015/06/11
- 06/10: packages: Make 'location' field innate., Ludovic Courtès, 2015/06/11
- 08/10: tests: Write the random seed to the error port., Ludovic Courtès, 2015/06/11
- 10/10: tests: Avoid sequence of zero expressions., Ludovic Courtès, 2015/06/11
- 09/10: records: Remove unnecessary 'begin'., Ludovic Courtès, 2015/06/11