Message ID | 22471a74b258f7169961898eed9e18cee7504f60.1687816734.git.mirai@makinata.eu |
---|---|
State | New |
Headers | show |
Series | Service subsystem improvements | expand |
Hi, Bruno Victal <mirai@makinata.eu> writes: > * gnu/services/configuration.scm > (define-configuration-helper, normalize-extra-args): Use #f instead of %unset-value. > --- > gnu/services/configuration.scm | 26 +++++++++++++------------- > 1 file changed, 13 insertions(+), 13 deletions(-) > > diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm > index 367b85c1be..dafe72f4fe 100644 > --- a/gnu/services/configuration.scm > +++ b/gnu/services/configuration.scm > @@ -190,32 +190,32 @@ (define (define-configuration-helper serialize? serializer-prefix syn) > (define (normalize-extra-args s) > "Extract and normalize arguments following @var{doc}." > (let loop ((s s) > - (sanitizer* %unset-value) > - (serializer* %unset-value)) > + (sanitizer* #f) > + (serializer* #f)) > (syntax-case s (sanitizer serializer empty-serializer) > (((sanitizer proc) tail ...) > - (if (maybe-value-set? sanitizer*) > - (syntax-violation 'sanitizer "duplicate entry" > - #'proc) > + (if sanitizer* > + (syntax-violation 'sanitizer > + "duplicate entry" #'proc) > (loop #'(tail ...) #'proc serializer*))) > (((serializer proc) tail ...) > - (if (maybe-value-set? serializer*) > - (syntax-violation 'serializer "duplicate or conflicting entry" > - #'proc) > + (if serializer* > + (syntax-violation 'serializer > + "duplicate or conflicting entry" #'proc) > (loop #'(tail ...) sanitizer* #'proc))) > ((empty-serializer tail ...) > - (if (maybe-value-set? serializer*) > + (if serializer* > (syntax-violation 'empty-serializer > "duplicate or conflicting entry" #f) > (loop #'(tail ...) sanitizer* #'empty-serializer))) > (() ; stop condition The above LGTM. > (values (list sanitizer* serializer*))) > ((proc) ; TODO: deprecated, to be removed. > - (null? (filter-map maybe-value-set? (list sanitizer* serializer*))) > + (every not (list sanitizer* serializer*)) Alternatively, using DeMorgan's law: (not (or sanitizer* serializer*)) > (begin > (warning #f (G_ "specifying serializers after documentation is \ > deprecated, use (serializer ~a) instead~%") (syntax->datum #'proc)) > - (values (list %unset-value #'proc))))))) > + (values (list #f #'proc))))))) > > (syntax-case syn () > ((_ stem (field field-type+def doc extra-args ...) ...) > @@ -239,11 +239,11 @@ (define (define-configuration-helper serialize? serializer-prefix syn) > default-value)) > #'((field-type def) ...))) > ((field-sanitizer ...) > - (map maybe-value #'(sanitizer* ...))) > + #'(sanitizer* ...)) > ((field-serializer ...) > (map (lambda (type proc) > (and serialize? > - (or (maybe-value proc) > + (or proc I haven't applied it locally so may be out of context, but how do we ensure here that sanitizer and proc aren't set to #f before calling them?
Hi Maxim, Maxim Cournoyer <maxim.cournoyer@gmail.com> writes: > Bruno Victal <mirai@makinata.eu> writes: >> (begin >> (warning #f (G_ "specifying serializers after documentation is \ >> deprecated, use (serializer ~a) instead~%") (syntax->datum #'proc)) >> - (values (list %unset-value #'proc))))))) >> + (values (list #f #'proc))))))) >> >> (syntax-case syn () >> ((_ stem (field field-type+def doc extra-args ...) ...) >> @@ -239,11 +239,11 @@ (define (define-configuration-helper serialize? serializer-prefix syn) >> default-value)) >> #'((field-type def) ...))) >> ((field-sanitizer ...) >> - (map maybe-value #'(sanitizer* ...))) >> + #'(sanitizer* ...)) >> ((field-serializer ...) >> (map (lambda (type proc) >> (and serialize? >> - (or (maybe-value proc) >> + (or proc > > I haven't applied it locally so may be out of context, but how do we > ensure here that sanitizer and proc aren't set to #f before calling > them? In the (or proc …) clause the logic is still equivalent to the previous (maybe-value proc) wrapped one. There's no problem with proc being #f as it either means that the field is marked as `no-serialization' or it will use the “default” serializers that appears latter within the (or …) clause. For sanitizers it boils down to this check further down: --8<---------------cut here---------------start------------->8--- ;; Define field validation macros. #,@(filter-map (lambda (name pred sanitizer) (if sanitizer #f (default-field-sanitizer name pred))) #'(field ...) #'(field-predicate ...) #'(field-sanitizer ...)) --8<---------------cut here---------------end--------------->8--- So if a custom sanitizer wasn't provided (which is marked internally as #f) then this filter-map will take care of defining a default one for it.
diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index 367b85c1be..dafe72f4fe 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -190,32 +190,32 @@ (define (define-configuration-helper serialize? serializer-prefix syn) (define (normalize-extra-args s) "Extract and normalize arguments following @var{doc}." (let loop ((s s) - (sanitizer* %unset-value) - (serializer* %unset-value)) + (sanitizer* #f) + (serializer* #f)) (syntax-case s (sanitizer serializer empty-serializer) (((sanitizer proc) tail ...) - (if (maybe-value-set? sanitizer*) - (syntax-violation 'sanitizer "duplicate entry" - #'proc) + (if sanitizer* + (syntax-violation 'sanitizer + "duplicate entry" #'proc) (loop #'(tail ...) #'proc serializer*))) (((serializer proc) tail ...) - (if (maybe-value-set? serializer*) - (syntax-violation 'serializer "duplicate or conflicting entry" - #'proc) + (if serializer* + (syntax-violation 'serializer + "duplicate or conflicting entry" #'proc) (loop #'(tail ...) sanitizer* #'proc))) ((empty-serializer tail ...) - (if (maybe-value-set? serializer*) + (if serializer* (syntax-violation 'empty-serializer "duplicate or conflicting entry" #f) (loop #'(tail ...) sanitizer* #'empty-serializer))) (() ; stop condition (values (list sanitizer* serializer*))) ((proc) ; TODO: deprecated, to be removed. - (null? (filter-map maybe-value-set? (list sanitizer* serializer*))) + (every not (list sanitizer* serializer*)) (begin (warning #f (G_ "specifying serializers after documentation is \ deprecated, use (serializer ~a) instead~%") (syntax->datum #'proc)) - (values (list %unset-value #'proc))))))) + (values (list #f #'proc))))))) (syntax-case syn () ((_ stem (field field-type+def doc extra-args ...) ...) @@ -239,11 +239,11 @@ (define (define-configuration-helper serialize? serializer-prefix syn) default-value)) #'((field-type def) ...))) ((field-sanitizer ...) - (map maybe-value #'(sanitizer* ...))) + #'(sanitizer* ...)) ((field-serializer ...) (map (lambda (type proc) (and serialize? - (or (maybe-value proc) + (or proc (if serializer-prefix (id #'stem serializer-prefix #'serialize- type) (id #'stem #'serialize- type)))))