GNU bug report logs - #56799
(gnu services configuration) usage of *unspecified* is problematic

Previous Next

Package: guix;

Reported by: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Date: Wed, 27 Jul 2022 16:25:02 UTC

Severity: important

Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #137 received at 56799 <at> debbugs.gnu.org (full text, mbox):

From: Attila Lendvai <attila <at> lendvai.name>
To: 56799 <at> debbugs.gnu.org
Cc: Attila Lendvai <attila <at> lendvai.name>
Subject: [PATCH 3/5] services: configuration: Add maybe-value exported
 procedure.
Date: Wed, 24 Aug 2022 14:40:40 +0200
* 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





This bug report was last modified 2 years and 327 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.