Subject: Re: [bug#54674] [PATCH] services: configuration: Use *unspecified* instead of 'disabled.

From: Attila Lendvai <[email-masked]>
Date: Mon, 04 Apr 2022 07:46:15 +0000

> > 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) "")