From patchwork Mon Apr 4 07:46:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Attila Lendvai X-Patchwork-Id: 38305 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 37F5427BBEA; Mon, 4 Apr 2022 08:49:14 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 56A1927BBE9 for ; Mon, 4 Apr 2022 08:49:13 +0100 (BST) Received: from localhost ([::1]:39256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nbHSa-00008o-Fg for patchwork@mira.cbaines.net; Mon, 04 Apr 2022 03:49:12 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36750) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nbHQU-0007go-Ok for guix-patches@gnu.org; Mon, 04 Apr 2022 03:47:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:56496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nbHQU-0000Mi-FU for guix-patches@gnu.org; Mon, 04 Apr 2022 03:47:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nbHQU-0005tW-Bz for guix-patches@gnu.org; Mon, 04 Apr 2022 03:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54674] [PATCH] services: configuration: Use *unspecified* instead of 'disabled. Resent-From: Attila Lendvai Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 04 Apr 2022 07:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54674 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxime Devos Cc: 54674@debbugs.gnu.org Received: via spool by 54674-submit@debbugs.gnu.org id=B54674.164905839122621 (code B ref 54674); Mon, 04 Apr 2022 07:47:02 +0000 Received: (at 54674) by debbugs.gnu.org; 4 Apr 2022 07:46:31 +0000 Received: from localhost ([127.0.0.1]:50393 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbHPz-0005sn-1B for submit@debbugs.gnu.org; Mon, 04 Apr 2022 03:46:31 -0400 Received: from mail-40136.proton.ch ([185.70.40.136]:39590) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nbHPv-0005sV-H9 for 54674@debbugs.gnu.org; Mon, 04 Apr 2022 03:46:29 -0400 Date: Mon, 04 Apr 2022 07:46:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lendvai.name; s=protonmail3; t=1649058380; bh=Jnspcnu+ijoLrm7+aaq0l9GoAdpOCnA4lkwn+HfDreQ=; h=Date:To:From:Cc:Reply-To:Subject:Message-ID:In-Reply-To: References:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID; b=BubNVr7VmxnVW7ecTau8j5+Wo1XX+IiKAqzizthiTvU/hbSG2SI2GoBFOhOw073PR JLXz47RPHQs+oo+0gjqDfjLW9rVijwqD3qFT+Sq8sii0njt2rH3dLjoWNHI133l8MS /3ycLrYxZMwRy9TsikB6oHTHL6vmBIrojD6e6ZdqsHBJUzOdkq8vSa0vaSbmaUUJFV 0kGyzwcYR5e7GhjaZdqhiNY8K9inU4AvErcbWT6irWyf/2YDGv2pWOgF0YWj1vGzTD 7fJvv9KaPuT+xAZ0ufGHmVmehEaYgkDAEDFQAU5X6e9LP0YjhpCJLvRCncLi8YsRc/ BiqmsG0mmcpfA== From: Attila Lendvai Message-ID: In-Reply-To: <2f39bf8cd56b3019026e43532b2f7b937de99b7e.camel@telenet.be> References: <20220401191957.16624-1-attila@lendvai.name> <2f39bf8cd56b3019026e43532b2f7b937de99b7e.camel@telenet.be> MIME-Version: 1.0 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: , Reply-To: Attila Lendvai Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches > > the reason i didn't do the (field1 maybe-string "") syntax *i.e. no > > parens around maybe-string), is that i couldn't convince the hygienic > > macro system about it. > > Do you have some non-working code? Maybe I can make it work ... thank you for your kind offer Maxime! i have attached a half-baked patch. it should also resolve your other nice catch of my mistaken use of UNSPECIFIED? on syntax objects. in this change i try to introduce a codepath for a canonical form for DEFINE-CONFIGURATION fields, but it won't work this way, because this way the SYNTAX-CASE forms will only match when *every* field is of the specified shape. the solution is probably in the direction of introducing a new DEFINE-CONFIGURATION-HELPER/FIELD somehow, but hygienic macros are a rather new territory for me... as for the (threads (number 5)) change: i'd rather not do it in this commit to try to keep it as much idempotent wrt behavior as possible. --- • attila lendvai • PGP: 963F 5D5F 45C7 DFCD 0A39 -- “The important thing is to not stop questioning. Curiosity has its own reason for existing.” — Albert Einstein (1879–1955) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index 325ef6e0ac..28dc314301 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -165,7 +165,7 @@ (define-maybe stem (no-serialization))) (define (define-configuration-helper serialize? serializer-prefix syn) (syntax-case syn () - ((_ stem (field (field-type def ...) doc custom-serializer ...) ...) + ((_ stem (field (field-type def) doc custom-serializer ...) ...) (with-syntax (((field-getter ...) (map (lambda (field) (id #'stem #'stem #'- field)) @@ -205,9 +205,7 @@ (define-record-type* #,(id #'stem #'< #'stem #'>) source-properties->location)) (innate)) #,@(map (lambda (name getter def) - (if (unspecified? (syntax->datum def)) - #`(#,name #,getter) - #`(#,name #,getter (default #,def)))) + #`(#,name #,getter (default #,def))) #'(field ...) #'(field-getter ...) #'(field-default ...))) @@ -231,7 +229,13 @@ (define-syntax-rule (stem arg (... ...)) (let ((conf (#,(id #'stem #'% #'stem) arg (... ...)))) (validate-configuration conf #,(id #'stem #'stem #'-fields)) - conf))))))) + conf))))) + ;; TODO This does not work, because it matches when *every* field is of + ;; this form. + ((_ stem (field (field-type) doc custom-serializer ...) ...) + (stem (field (field-type *unspecified*) doc custom-serializer ...) ...)) + ((_ stem (field field-type doc custom-serializer ...) ...) + (stem (field (field-type *unspecified*) doc custom-serializer ...) ...)))) (define no-serialization ;syntactic keyword for 'define-configuration' '(no serialization)) @@ -239,27 +243,19 @@ (define no-serialization ;syntactic keyword for 'define-configuration' (define-syntax define-configuration (lambda (s) (syntax-case s (no-serialization prefix) - ((_ stem (field (field-type def ...) doc custom-serializer ...) ... - (no-serialization)) - (define-configuration-helper - #f #f #'(_ stem (field (field-type def ...) doc custom-serializer ...) - ...))) - ((_ stem (field (field-type def ...) doc custom-serializer ...) ... - (prefix serializer-prefix)) - (define-configuration-helper - #t #'serializer-prefix #'(_ stem (field (field-type def ...) - doc custom-serializer ...) - ...))) - ((_ stem (field (field-type def ...) doc custom-serializer ...) ...) - (define-configuration-helper - #t #f #'(_ stem (field (field-type def ...) doc custom-serializer ...) - ...)))))) + ((_ stem fields ... (no-serialization)) + (define-configuration-helper #f #f + #'(_ stem fields ...))) + ((_ stem fields ... (prefix serializer-prefix)) + (define-configuration-helper #t #'serializer-prefix + #'(_ stem fields ...))) + ((_ stem fields ...) + (define-configuration-helper #t #f + #'(_ stem fields ...)))))) (define-syntax-rule (define-configuration/no-serialization - stem (field (field-type def ...) - doc custom-serializer ...) ...) - (define-configuration stem (field (field-type def ...) - doc custom-serializer ...) ... + stem (field type-and-def doc custom-serializer ...) ...) + (define-configuration stem (field type-and-def doc custom-serializer ...) ... (no-serialization))) (define (empty-serializer field-name val) "")