From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id SAXVHmX9GmXZAQEA9RJhRA:P1 (envelope-from ) for ; Mon, 02 Oct 2023 19:27:01 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id SAXVHmX9GmXZAQEA9RJhRA (envelope-from ) for ; Mon, 02 Oct 2023 19:27:01 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E201E39AE7 for ; Mon, 2 Oct 2023 19:27:00 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=WpX3TooY; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1696267621; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=CA1xDYUbca+bUORs6JAQTHYQRuypRzhwZgGinO4uOms=; b=WNmFBQAvmc1qEwVyU1epsma6dcLRwgnx6MOj86qbUPi/2mlAK+kBU0o+tiOmk+QH89umEy wSc+YvA2Vin1cozTTHtKozYxFUiPsLkULDi1NXldcr0XcZj6RYoN7hUjXKsGnk+g5NvY6i pAJ2pBRv16QY+xvWaElGS2bBRJ8ALcb6CWAnWXUvgWm/lr/79aGugrMGWLjxzixKJIU8b5 vuO5MZAWvLMt4T7M6Zok3arzyIVXBb6Phk8anGN0NC4cOJpQ2wFi1a3Jzghre6n1ctdyns 3DnWeJr84HQQ9GhF7nCQRM3i6mlmDSMoOaZNbH+udYroeACXxJGuI/1oCszIuA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1696267621; a=rsa-sha256; cv=none; b=BAabcQq1l7HxBFlvXdGJ51z79iDqZGMyYl+2HwsHXkDLy8lQ7koO+fucy6ZgHgrH3keRI/ CTgoJ4cF2zJ8jqSAqen39D9+ruEbrnrnrqPV8bGPCuVk00ie4K3UUTTfe2ZbpueoMiuUHB KZXFGF4vje2yPTATczE5vRq7E4uSzIiYOcU8BLIaALZmZ9MfQELH3KaSIoDcolTcApDH/Z BaoGp4m5h/ibxuOu44BlZEncH5MzZFsTUQsMylPE2sQsF+f802TL6u0euNVy/EJdZD/16M RN7RyKDhSVVs3H1HOEe3HQesgI99cVuHcmyzKpljZfsLqebFfBzrToibcFqtMw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20230601 header.b=WpX3TooY; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qnMgz-00066z-OQ; Mon, 02 Oct 2023 13:26:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qnMgv-00063v-Sc for guix-patches@gnu.org; Mon, 02 Oct 2023 13:26:45 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qnMgv-0006Ua-KL for guix-patches@gnu.org; Mon, 02 Oct 2023 13:26:45 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qnMhB-0001HK-Pu for guix-patches@gnu.org; Mon, 02 Oct 2023 13:27:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#63985] [PATCH RFC 0/5] Generic INI serializer & SRFI-171 for define-configuration Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 02 Oct 2023 17:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 63985 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Bruno Victal Cc: 63985@debbugs.gnu.org Received: via spool by 63985-submit@debbugs.gnu.org id=B63985.16962675834863 (code B ref 63985); Mon, 02 Oct 2023 17:27:01 +0000 Received: (at 63985) by debbugs.gnu.org; 2 Oct 2023 17:26:23 +0000 Received: from localhost ([127.0.0.1]:37876 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnMgY-0001GK-Ot for submit@debbugs.gnu.org; Mon, 02 Oct 2023 13:26:23 -0400 Received: from mail-qk1-x731.google.com ([2607:f8b0:4864:20::731]:60600) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qnMgW-0001G8-W8 for 63985@debbugs.gnu.org; Mon, 02 Oct 2023 13:26:21 -0400 Received: by mail-qk1-x731.google.com with SMTP id af79cd13be357-77575233633so3840185a.0 for <63985@debbugs.gnu.org>; Mon, 02 Oct 2023 10:26:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696267558; x=1696872358; darn=debbugs.gnu.org; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=CA1xDYUbca+bUORs6JAQTHYQRuypRzhwZgGinO4uOms=; b=WpX3TooYUc7G98B4D7QISaKjWvZedB2kw2MOB1RykLos22Z+mvd5nnP+Fvh6aty7Yi 5kiXsgr4josJpER6gnuXfwNyZY68D+wRGenfn8z9pCULq4cZKYvkOIkY3LM+0B2QE2NA 46i9sR13qCadOhNFav+3Nmky+ZdJbRVcx01+Um/cSKslJeXA+Naq+lwCmJRlnOIowNyD ZLtrYzKySGkbzv+zHqH2PFUtDFKpr08phAkLRjK0I7sOCYH7q+wIZIh1iB+JLIVqRKx2 iZkAPKP37PolZmTf2umO2vKJq/fmv51jzlSndrK+BmLTVamKu1kUyWD1zeUdDvTXY3gY q78g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696267558; x=1696872358; h=mime-version:user-agent:message-id:in-reply-to:date:references :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CA1xDYUbca+bUORs6JAQTHYQRuypRzhwZgGinO4uOms=; b=RtlNRoG1pc6J79MGw9r/YSsTxdHk1Zc0VkYY/hi0XQj0MQO9dGs/yn80Up8in4y4R5 2mcx+HHool0ocruqHDco3lQkFqC0/ZmTBHEwBCzKOkBgDTjo6pNofnKNbcOWNPOVoHPT Co2m5pYyKsLg4/JISjamS4AIZcdfHI7/WzWTU57PbTmqu25SyFtBI/wpeb1m4dcw02Kd +uFG8O2PHXPhYuCChDEQAnSzYBTtEqD7lxQJ1QwY7CJfyfmX9GczX6djSssvS3GwEg8B 579l1XvHVDd+k/YzV2QV4e4mJ7MfJKiYaNzQ893TOzV0F7YNzNDxAPvXEynT4A7C9m4d Z1mw== X-Gm-Message-State: AOJu0Yx8SDYzwLPasJRkhao0pP3Xl2SqcK10zkZxo8/rw+RzXPYmo2j6 4XWKRcINfpwJ/Z1ggh45PVF3xsKudzw= X-Google-Smtp-Source: AGHT+IFo11IZWIqUhPxK2qhfFIhr6PmVzMfZxWHvy4X1OSIZ1C8pWFlNdtfytAIO+rNNPB9QS8eEpw== X-Received: by 2002:a05:620a:24c4:b0:775:9e64:f5c9 with SMTP id m4-20020a05620a24c400b007759e64f5c9mr6916965qkn.2.1696267558005; Mon, 02 Oct 2023 10:25:58 -0700 (PDT) Received: from hurd (dsl-10-136-90.b2b2c.ca. [72.10.136.90]) by smtp.gmail.com with ESMTPSA id n18-20020ae9c312000000b0076f13783743sm2226926qkg.92.2023.10.02.10.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 10:25:57 -0700 (PDT) From: Maxim Cournoyer References: Date: Mon, 02 Oct 2023 13:25:56 -0400 In-Reply-To: (Bruno Victal's message of "Mon, 26 Jun 2023 22:59:28 +0100") Message-ID: <871qed3pi3.fsf_-_@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: 5.75 X-Migadu-Spam-Score: 5.75 X-Migadu-Scanner: mx1.migadu.com X-Migadu-Queue-Id: E201E39AE7 X-TUID: wZHjM5iRQeiQ Hello, Bruno Victal writes: > Introduces 'base-transducer', a SRFI-171 based transducer that can be used as a > starting point for writing custom configuration record serializing procedures. > > This also fixes the symbol maybe-value serialization test case. > > * gnu/services/configuration.scm (empty-serializer?): New predicate. > (base-transducer, tfilter-maybe-value): New procedure. > (serialize-configuration): Adapt to use base-transducer. > > * gnu/services/telephony.scm (jami-account->alist): Use transducers to skip > fields that are unserializable or whose field maybe-value is unset. > > * tests/services/configuration.scm: Remove test-expect-fail. Pretty cool stuff! > --- > gnu/services/configuration.scm | 29 ++++++++++++++++++++++++----- > gnu/services/telephony.scm | 27 +++++++++++++-------------- > tests/services/configuration.scm | 6 +----- > 3 files changed, 38 insertions(+), 24 deletions(-) > > diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm > index dafe72f4fe..cd2cb8318b 100644 > --- a/gnu/services/configuration.scm > +++ b/gnu/services/configuration.scm > @@ -42,6 +42,7 @@ (define-module (gnu services configuration) > #:use-module (srfi srfi-26) > #:use-module (srfi srfi-34) > #:use-module (srfi srfi-35) > + #:use-module (srfi srfi-171) > #:export (configuration-field > configuration-field-name > configuration-field-type > @@ -59,6 +60,10 @@ (define-module (gnu services configuration) > define-configuration/no-serialization > no-serialization > > + empty-serializer? > + tfilter-maybe-value > + base-transducer > + > serialize-configuration > define-maybe > define-maybe/no-serialization > @@ -125,13 +130,27 @@ (define-record-type* > (default-value-thunk configuration-field-default-value-thunk) > (documentation configuration-field-documentation)) > > +(define (empty-serializer? field) > + (eq? empty-serializer > + (configuration-field-serializer field))) > + > +(define (tfilter-maybe-value config) > + (tfilter (lambda (field) > + (let ((field-value ((configuration-field-getter field) config))) > + (maybe-value-set? field-value))))) > + > +(define (base-transducer config) > + (compose (tremove empty-serializer?) > + ;; Only serialize fields whose value isn't '%unset-marker%. > + (tfilter-maybe-value config) > + (tmap (lambda (field) > + ((configuration-field-serializer field) > + (configuration-field-name field) > + ((configuration-field-getter field) config)))))) > + Please add docstrings. > (define (serialize-configuration config fields) > #~(string-append > - #$@(map (lambda (field) > - ((configuration-field-serializer field) > - (configuration-field-name field) > - ((configuration-field-getter field) config))) > - fields))) > + #$@(list-transduce (base-transducer config) rcons fields))) > While at it, please add a docstring for this procedure as well. > (define-syntax-rule (id ctx parts ...) > "Assemble PARTS into a raw (unhygienic) identifier." > 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 > @@ -37,6 +37,7 @@ (define-module (gnu services telephony) > #:use-module (srfi srfi-1) > #:use-module (srfi srfi-2) > #:use-module (srfi srfi-26) > + #:use-module (srfi srfi-171) > #:use-module (ice-9 format) > #:use-module (ice-9 match) > #:export (jami-account > @@ -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? > (define (jami-account-list? val) > (and (list? val) > diff --git a/tests/services/configuration.scm b/tests/services/configuration.scm > index 8ad5907f37..40a4e74b4d 100644 > --- a/tests/services/configuration.scm > +++ b/tests/services/configuration.scm > @@ -337,13 +337,9 @@ (define-maybe symbol) > (define-configuration config-with-maybe-symbol > (protocol maybe-symbol "")) > > -;;; Maybe symbol values are currently seen as serializable, because the > -;;; unspecified value is '%unset-marker%, which is a symbol itself. > -;;; TODO: Remove expected fail marker after resolution. > -(test-expect-fail 1) > (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? -- Thanks, Maxim