summaryrefslogtreecommitdiff
path: root/guix/utils.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-07-01 17:32:03 +0200
committerLudovic Courtès <ludo@gnu.org>2012-07-03 21:59:56 +0200
commit8fd5bd2b69b51e370144f26c01201a178c024483 (patch)
tree3889c1a00d30d2c5e51286c83536ee71c5a01149 /guix/utils.scm
parente4c245f8a5f6b6485f980b9c4274909ee8ef567a (diff)
downloadgnu-guix-8fd5bd2b69b51e370144f26c01201a178c024483.tar
gnu-guix-8fd5bd2b69b51e370144f26c01201a178c024483.tar.gz
define-record-type*: Add `letrec*' behavior.
* guix/utils.scm (define-record-type*)[make-syntactic-constructor]: Bind all the ((FIELD VALUE) ...) in a `letrec*'. Adjust `field-value' accordingly. * tests/utils.scm ("define-record-type* with letrec* behavior"): New test.
Diffstat (limited to 'guix/utils.scm')
-rw-r--r--guix/utils.scm29
1 files changed, 14 insertions, 15 deletions
diff --git a/guix/utils.scm b/guix/utils.scm
index ed13bae307..3d92bac9cc 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -479,20 +479,18 @@ tuples."
(lambda (s)
(syntax-case s expected
((_ (field value) (... ...))
- (let ((fields (map syntax->datum #'(field (... ...))))
- (inits (map (match-lambda
- ((f v)
- (list (syntax->datum f) v)))
- #'((field value) (... ...))))
- (dflt (map (match-lambda
- ((f v)
- (list (syntax->datum f) v)))
- #'defaults)))
-
- (define (field-value f)
- (match (assoc f inits)
- ((_ v) v)
- (#f (car (assoc-ref dflt f)))))
+ (let ((fields (map syntax->datum #'(field (... ...))))
+ (dflt (map (match-lambda
+ ((f v)
+ (list (syntax->datum f) v)))
+ #'defaults)))
+
+ (define (field-value f)
+ (or (and=> (find (lambda (x)
+ (eq? f (car (syntax->datum x))))
+ #'((field value) (... ...)))
+ car)
+ (car (assoc-ref dflt (syntax->datum f)))))
(let-syntax ((error*
(syntax-rules ()
@@ -503,7 +501,8 @@ tuples."
s)))))
(let ((fields (append fields (map car dflt))))
(cond ((lset= eq? fields 'expected)
- #`(ctor #,@(map field-value 'expected)))
+ #`(letrec* ((field value) (... ...))
+ (ctor #,@(map field-value 'expected))))
((pair? (lset-difference eq? fields 'expected))
(error* "extraneous field initializers ~a"
(lset-difference eq? fields 'expected)))