Subject: Re: [PATCH 4/5] services: pulseaudio: Add an extra-script-files configuration field.

From: Maxim Cournoyer <[email-masked]>
Date: Thu, 24 Feb 2022 11:25:03 -0500

Hi Liliana,

Liliana Marie Prikler <[email-masked]> writes:

[...]

> Note that file-like->name serves multiple duties here.  In my opinion
> it'd be better to
>
> (define (file-like-name file)
>   ((match file
>      ((? local-file?) local-file-name)
>      ((? plain-file?) plain-file-name)
>      ((? computed-file?) computed-file-name)
>      [...]
>      (_ (const #f))) ; alternatively raise an error
>    file))
>
> That at least decouples it from the burden of having to check whether
> it is a valid pulseaudio script file name, which makes it reusable
> elsewhere.

I've modified it like so:

--8<---------------cut here---------------start------------->8---
modified   gnu/services/sound.scm
@@ -154,21 +154,24 @@ (define (extra-script-files->file-union extra-script-files)
   "Return a G-exp obtained by processing EXTRA-SCRIPT-FILES with FILE-UNION."

   (define (file-like->name file)
-    (let ((name (match file
-                  ((? local-file?)
-                   (local-file-name file))
-                  ((? plain-file?)
-                   (plain-file-name file))
-                  ((? computed-file?)
-                   (computed-file-name file))
-                  (_ (leave (G_ "~a is not a local-file, plain-file or \
-computed-file object~%") file)))))
-      (unless (string-suffix? ".pa" name)
-        (leave (G_ "`~a' lacks the required `.pa' file name extension~%")
-               name))
-      name))
-
-  (let ((labels (map file-like->name extra-script-files)))
+    (match file
+      ((? local-file?)
+       (local-file-name file))
+      ((? plain-file?)
+       (plain-file-name file))
+      ((? computed-file?)
+       (computed-file-name file))
+      (_ (leave (G_ "~a is not a local-file, plain-file or \
+computed-file object~%") file))))
+
+  (define (assert-pulseaudio-script-file-name name)
+    (unless (string-suffix? ".pa" name)
+      (leave (G_ "`~a' lacks the required `.pa' file name extension~%") name))
+    name)
+
+  (let ((labels (map (compose assert-pulseaudio-script-file-name)
+                              file-like->name
+                     extra-script-files)))
     (file-union "default.pa.d" (zip labels extra-script-files))))
--8<---------------cut here---------------end--------------->8---

Thanks for the suggestion.

I'll be sending a v2 series soon.

Maxim