guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

environment variable handling cleanup ?


From: Vincent Legoll
Subject: environment variable handling cleanup ?
Date: Sun, 22 Mar 2020 15:40:16 +0100

Hello,

as I'm trying to ramp up my scheme & guix -fu, I'm wondering if
something along the lines of :

  (define* (env-prepend env-var value #:key (separator ":"))
    (let* ((env-val (or (getenv env-var) ""))
           (new-val (if (string-null? env-val)
                      value
                      (string-append value separator env-val))))
      (setenv env-var new-val)))

  (define* (env-append env-var value #:key (separator ":"))
    (let* ((env-val (or (getenv env-var) ""))
           (new-val (if (string-null? env-val)
                      value
                      (string-append env-val separator value))))
      (setenv env-var new-val)))

Would be useful / wanted / controversial ?

My crude approximation tells me there is 1 or 2 hundred such
instances that this could replace.

I expect this would turn ~2 SLOCs into one at each site, so the
gains are not huge compared to the size of guix source code base.

The readability enhancement is also up to debate.

There's also the added (or (getenv ...) "") which is not present in
all target cases.

Another question is the usefulness of the separator parameter,
as I think all target cases use ":", so hardcoding it would be a
sensible choice.

WDYT ?

-- 
Vincent Legoll



reply via email to

[Prev in Thread] Current Thread [Next in Thread]