On Wed 30 Nov 2016 14:09, l...@gnu.org (Ludovic Courtès) writes: >> (define (validate-configuration config fields) >> (for-each (lambda (field) >> (let ((val ((configuration-field-getter field) config))) >> - (unless ((configuration-field-predicate field) val) >> + (unless (or (not val) ((configuration-field-predicate >> field) val)) >> (configuration-field-error >> (configuration-field-name field) val)))) > > Here you’re assuming that when VAL is #f, it’s necessary invalid, an > assumption that’s questionable and wasn’t made until now. > > Can you instead change your own field predicate to do that?
Agreed; the usual way to do this is to define the default value as a sentinel value that your field predicate rejects. E.g. (define unset-field (list 'unset-field)) You'd make the default value be `unset-field' (by reference). Then assuming you defined a field of type "foo" then assuming you have an associated predicate `foo?', you can do (define (predicate/not-unset pred) (lambda (x) (and (not (eq? x unset-field)) (pred x)))) (define foo? (predicate/not-unset foo?)) Andy