unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Vincent Legoll <vincent.legoll@gmail.com>
To: guix-devel <guix-devel@gnu.org>
Subject: environment variable handling cleanup ?
Date: Sun, 22 Mar 2020 15:40:16 +0100	[thread overview]
Message-ID: <CAEwRq=o2SvRPNU+QJMNA2T=g_Yzjf9m38FFY+CfSdJzFZdg4_g@mail.gmail.com> (raw)

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	other threads:[~2020-03-22 14:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-22 14:40 Vincent Legoll [this message]
2020-03-23  8:54 ` environment variable handling cleanup ? Hartmut Goebel
2020-03-28  8:06   ` Vincent Legoll

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAEwRq=o2SvRPNU+QJMNA2T=g_Yzjf9m38FFY+CfSdJzFZdg4_g@mail.gmail.com' \
    --to=vincent.legoll@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).