From mboxrd@z Thu Jan 1 00:00:00 1970 From: Vincent Legoll Subject: environment variable handling cleanup ? Date: Sun, 22 Mar 2020 15:40:16 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:60932) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jG1mA-0001tE-1f for guix-devel@gnu.org; Sun, 22 Mar 2020 10:40:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jG1m9-0006SI-0o for guix-devel@gnu.org; Sun, 22 Mar 2020 10:40:29 -0400 Received: from mail-io1-xd33.google.com ([2607:f8b0:4864:20::d33]:34360) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jG1m8-0006S9-Sd for guix-devel@gnu.org; Sun, 22 Mar 2020 10:40:28 -0400 Received: by mail-io1-xd33.google.com with SMTP id h131so11485858iof.1 for ; Sun, 22 Mar 2020 07:40:28 -0700 (PDT) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane-mx.org@gnu.org Sender: "Guix-devel" To: guix-devel 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