records: Use keyword parameters for 'make-syntactic-constructor'.
* guix/records.scm (define-record-type*)[make-syntactic-constructor]: Turn THUNKED and DEFAULTS into keyword arguments. Adjust caller accordingly. Declare 'thunked' and 'defaults' local variables.master
parent
eb497b6616
commit
9b543456d7
|
@ -78,7 +78,8 @@ It is possible to copy an object 'x' created with 'thing' like this:
|
||||||
This expression returns a new object equal to 'x' except for its 'name'
|
This expression returns a new object equal to 'x' except for its 'name'
|
||||||
field."
|
field."
|
||||||
|
|
||||||
(define (make-syntactic-constructor type name ctor fields thunked defaults)
|
(define* (make-syntactic-constructor type name ctor fields
|
||||||
|
#:key thunked defaults)
|
||||||
"Make the syntactic constructor NAME for TYPE, that calls CTOR, and
|
"Make the syntactic constructor NAME for TYPE, that calls CTOR, and
|
||||||
expects all of FIELDS to be initialized. DEFAULTS is the list of
|
expects all of FIELDS to be initialized. DEFAULTS is the list of
|
||||||
FIELD/DEFAULT-VALUE tuples, and THUNKED is the list of identifiers of
|
FIELD/DEFAULT-VALUE tuples, and THUNKED is the list of identifiers of
|
||||||
|
@ -219,7 +220,10 @@ thunked fields."
|
||||||
(syntax-case s ()
|
(syntax-case s ()
|
||||||
((_ type syntactic-ctor ctor pred
|
((_ type syntactic-ctor ctor pred
|
||||||
(field get options ...) ...)
|
(field get options ...) ...)
|
||||||
(let* ((field-spec #'((field get options ...) ...)))
|
(let* ((field-spec #'((field get options ...) ...))
|
||||||
|
(thunked (filter-map thunked-field? field-spec))
|
||||||
|
(defaults (filter-map field-default-value
|
||||||
|
#'((field options ...) ...))))
|
||||||
(with-syntax (((field-spec* ...)
|
(with-syntax (((field-spec* ...)
|
||||||
(map field-spec->srfi-9 field-spec))
|
(map field-spec->srfi-9 field-spec))
|
||||||
((thunked-field-accessor ...)
|
((thunked-field-accessor ...)
|
||||||
|
@ -236,10 +240,8 @@ thunked fields."
|
||||||
(begin thunked-field-accessor ...)
|
(begin thunked-field-accessor ...)
|
||||||
#,(make-syntactic-constructor #'type #'syntactic-ctor #'ctor
|
#,(make-syntactic-constructor #'type #'syntactic-ctor #'ctor
|
||||||
#'(field ...)
|
#'(field ...)
|
||||||
(filter-map thunked-field? field-spec)
|
#:thunked thunked
|
||||||
(filter-map field-default-value
|
#:defaults defaults))))))))
|
||||||
#'((field options ...)
|
|
||||||
...))))))))))
|
|
||||||
|
|
||||||
(define* (alist->record alist make keys
|
(define* (alist->record alist make keys
|
||||||
#:optional (multiple-value-keys '()))
|
#:optional (multiple-value-keys '()))
|
||||||
|
|
Loading…
Reference in New Issue