guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] gnu: Add Kerberos client service.


From: Andy Wingo
Subject: Re: [PATCH] gnu: Add Kerberos client service.
Date: Wed, 30 Nov 2016 14:52:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

On Wed 30 Nov 2016 14:09, address@hidden (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]