From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 24 08:41:12 2022 Received: (at 56799) by debbugs.gnu.org; 24 Aug 2022 12:41:12 +0000 Received: from localhost ([127.0.0.1]:45917 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQph2-00081H-7h for submit@debbugs.gnu.org; Wed, 24 Aug 2022 08:41:12 -0400 Received: from mail-ej1-f52.google.com ([209.85.218.52]:43882) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oQph0-00080x-GP for 56799@debbugs.gnu.org; Wed, 24 Aug 2022 08:41:10 -0400 Received: by mail-ej1-f52.google.com with SMTP id gb36so33239661ejc.10 for <56799@debbugs.gnu.org>; Wed, 24 Aug 2022 05:41:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc; bh=BXzFccNAioTNrtwtKF1NfWTp3i9MpLbsWl+Ya2NR4ks=; b=h65RWbrEx/xIhskx/YUfaFc22T44XAOHALL3N3w9vV8Wx5FZYdCZQt7PyCjFxkxKfu Ds8NKAMe2gYlVh8lb+xyW04XDBrommgVBsugYVaiT/qKvTa6DUaDWpj6PG835VodqA74 yIwB9ziLpu88uuqhB39rQFB9szT21gGRqQAo+RSFDPGaQ/5tWHAUJTU8wrpFCwXq3Ttq 1sAOKY2UlSulVb94lTP+XL097SJvbOvB/FLhaGAyvnQKPHJa+X8DbY+/QwEGV1wRYVTb DVLS9A97iwbDkDqGEtRlsE3FBj5KYcG9Eu+ZFj7nIUh9h5FhJ1Mj3UXpODX2+KxZsykX Lr4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc; bh=BXzFccNAioTNrtwtKF1NfWTp3i9MpLbsWl+Ya2NR4ks=; b=O74iOwaTdt3VCkaUZVhRH9TVjkAJQTsFr6RZ9SbTPnQs/dxCGHAgoHdUYjAURYocFc bzCDl+6L5kbb4Kyt9aT2xZFtRG89ea/cIeG1Mv9x47GlSF2uaBpmgWnMMNI3hApe//6g lydsml65hxrp37xsPFlAfyk2l2GFFXGv0D1dN19brfz8o83DQ9dSAkY1K0YcDxsiCwbk N6DLRW68gW6rIZxTnPbi8EfdYtJAIM70YmLP/2FQhRRTMyq4Lt2yluokkR0k113PK2XJ IrxJ2ao8aVECqxY31MVReHMYrfQSBNR8ByJoN4tE9sIfNWih02MwGMCUTdokOL2puRc/ pcHg== X-Gm-Message-State: ACgBeo31kH0G9G32JOorTv+4X4yCNBrMlrWZk7sT0eWZuAQVvyrxa6VR /fTz+XtdBApkrbbdjm6xc/BhKiPOnuI= X-Google-Smtp-Source: AA6agR5q4YkHKQxam7o6gtZHMXj+4ct1MWtBumA2rZ84/YXQORAlV424r+dNIdQuJ4/SRBXxWFAGeQ== X-Received: by 2002:a17:906:eecb:b0:73c:5c85:142b with SMTP id wu11-20020a170906eecb00b0073c5c85142bmr2800691ejb.433.1661344864873; Wed, 24 Aug 2022 05:41:04 -0700 (PDT) Received: from localhost.localdomain ([2a02:ab88:7509:f780:ed82:a496:f55:e07b]) by smtp.gmail.com with ESMTPSA id f2-20020a17090631c200b006fee7b5dff2sm1114628ejf.143.2022.08.24.05.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 05:41:04 -0700 (PDT) From: Attila Lendvai To: 56799@debbugs.gnu.org Subject: [PATCH 3/5] services: configuration: Add maybe-value exported procedure. Date: Wed, 24 Aug 2022 14:40:40 +0200 Message-Id: <20220824124042.10959-3-attila@lendvai.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220824124042.10959-1-attila@lendvai.name> References: <20220824124042.10959-1-attila@lendvai.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 56799 Cc: Attila Lendvai X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) * gnu/services/configuration.scm (maybe-value): New procedure. --- gnu/services/configuration.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gnu/services/configuration.scm b/gnu/services/configuration.scm index a9426066b9..60965486a7 100644 --- a/gnu/services/configuration.scm +++ b/gnu/services/configuration.scm @@ -58,6 +58,7 @@ (define-module (gnu services configuration) define-maybe define-maybe/no-serialization %unset-value + maybe-value maybe-value-set? generate-documentation configuration->documentation @@ -315,6 +316,15 @@ (define (maybe-value-set? value) "Predicate to check whether a 'maybe' value was explicitly provided." (not (eq? %unset-value value))) +;; Ideally there should be a compiler macro for this predicate, that expands +;; to a conditional that only instantiates the default value when needed. +(define* (maybe-value value #:optional (default #f)) + "Returns VALUE, unless it is the unset value, in which case it returns +DEFAULT." + (if (maybe-value-set? value) + value + default)) + ;; A little helper to make it easier to document all those fields. (define (generate-documentation documentation documentation-name) (define (str x) (object->string x)) -- 2.35.1