[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#63985] [PATCH v3 02/11] services: configuration: Use transducers wi
From: |
Bruno Victal |
Subject: |
[bug#63985] [PATCH v3 02/11] services: configuration: Use transducers within serialize-configuration. (was : bug#63985: [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration) |
Date: |
Sat, 7 Oct 2023 14:39:17 +0100 |
User-agent: |
Mozilla Thunderbird |
On 2023-10-02 18:25, Maxim Cournoyer wrote:
> Bruno Victal <mirai@makinata.eu> writes:
>> diff --git a/gnu/services/telephony.scm b/gnu/services/telephony.scm
>> index 23ccb8d403..56b7772f58 100644
>> --- a/gnu/services/telephony.scm
>> +++ b/gnu/services/telephony.scm
>> @@ -204,22 +205,20 @@ (define (jami-account->alist jami-account-object)
>> ('rendezvous-point? "Account.rendezVous")
>> ('peer-discovery? "Account.peerDiscovery")
>> ('bootstrap-hostnames "Account.hostname")
>> - ('name-server-uri "RingNS.uri")
>> - (_ #f)))
>> + ('name-server-uri "RingNS.uri")))
>>
>> - (filter-map (lambda (field)
>> - (and-let* ((name (field-name->account-detail
>> + (define jami-account-transducer
>> + (compose (tremove empty-serializer?)
>> + (tfilter-maybe-value jami-account-object)
>> + (tmap (lambda (field)
>> + (let* ((name (field-name->account-detail
>> (configuration-field-name field)))
>> - (value ((configuration-field-serializer field)
>> - name ((configuration-field-getter field)
>> - jami-account-object)))
>> - ;; The define-maybe default serializer produces
>> an
>> - ;; empty string for unspecified values.
>> - (value* (if (string-null? value)
>> - #f
>> - value)))
>> - (cons name value*)))
>> - jami-account-fields))
>> + (value ((configuration-field-serializer field)
>> + name ((configuration-field-getter field)
>> + jami-account-object))))
>> + (cons name value))))))
>> +
>> + (list-transduce jami-account-transducer rcons jami-account-fields))
>
> Could you please state in a comment under "(define
> jami-account-transducer" why the base transducer doesn't suffice? It
> isn't obvious to me from a casual inspection. I guess it's because
> base-transducer is not recursive? Should it be?
This is because you're changing the field names of the JAMI-ACCOUNT record type
through `field-name->account-detail'.
Conventional serializers are (serializer (field-name value)) procedures and
this is
how `base-transducer' calls them. Here you want to do something of the sort
(serializer (translate-field-name name) value) so a custom transducer was
written to
account for this detour.
I wonder if we could simply this with some functional programming as discussed
in
[1] instead.
>> (test-equal "symbol maybe value serialization, unspecified"
>> ""
>> - (gexp->approximate-sexp
>> + (eval-gexp
>> (serialize-configuration (config-with-maybe-symbol)
>> config-with-maybe-symbol-fields)))
>
> That's nice, though I don't understand why gexp->approximate needs to be
> turned into eval-gexp?
Using `gexp->approximate-sexp' alone doesn't result in a evaluation of the
serialization process so eval-gexp has to be used in order to actually perform
this test.
[1]: Message-ID: <673081be-14c1-4864-9bd1-1cbc908823a6@makinata.eu>
Link:
<https://lists.gnu.org/archive/html/guix-patches/2023-10/msg00313.html>
--
Furthermore, I consider that nonfree software must be eradicated.
Cheers,
Bruno.
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02
- [bug#63985] [PATCH v3 02/11] services: configuration: Use transducers within serialize-configuration. (was : bug#63985: [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration),
Bruno Victal <=
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02
- [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration, Maxim Cournoyer, 2023/10/02