delorie.com/archives/browse.cgi   search  
Mail Archives: geda-user/2021/04/22/08:34:48

X-Authentication-Warning: delorie.com: mail set sender to geda-user-bounces using -f
X-Recipient: geda-user AT delorie DOT com
X-Mailer: exmh version 2.8.0 04/21/2012 with nmh-1.7+dev
X-Exmh-Isig-CompType: repl
X-Exmh-Isig-Folder: inbox
From: "karl AT aspodata DOT se [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
To: geda-user AT delorie DOT com
Subject: readlink in guile (Re: [geda-user] system wide config)
In-reply-to: <20210422091632.7178ff90@demon>
References: <20210417120805 DOT 37DAA824EAA0 AT turkos DOT aspodata DOT se> <YHrjzpKEMOvXREuY AT lepton> <20210417144426 DOT E4238824EAA0 AT turkos DOT aspodata DOT se> <YH4IPPe+k4MZJJkm AT lepton> <20210420004032 DOT 30A6980770A6 AT turkos DOT aspodata DOT se> <YH6T5zzhba9AqGX9 AT lepton> <20210420143556 DOT CC46580770AF AT turkos DOT aspodata DOT se> <20210420144634 DOT 1456180770AF AT turkos DOT aspodata DOT se> <20210422091632 DOT 7178ff90 AT demon>
Comments: In-reply-to "dmn (graahnul DOT grom AT gmail DOT com) [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
message dated "Thu, 22 Apr 2021 09:16:32 +0300."
Mime-Version: 1.0
Message-Id: <20210422123323.469F183D3FA8@turkos.aspodata.se>
Date: Thu, 22 Apr 2021 14:33:23 +0200 (CEST)
X-Virus-Scanned: ClamAV using ClamSMTP
Reply-To: geda-user AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: geda-user AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com

Dmitry:
> On Tue, 20 Apr 2021 16:46:34 +0200 (CEST)
> "karl AT aspodata DOT se [via geda-user AT delorie DOT com]" <geda-user AT delorie DOT com>
> wrote:
...
> > (define (readlink file)
> >   (let*
> >    (
> >     (port (open-input-pipe (string-append "readlink -f " file)))
> >     (str  (read-line port))
> >     (close-pipe port)
> >    )
> >    str
> >   )
> > )
...
> Karl, first of all, I'd like to thank you for not using the "dog's
> breakfast coding style" (TM)! :-)

What is that ?
Is it about all thoose {str|d}angling parentheses...

> Being not an expert in the bloody lisp programming language, I wonder
> does the call "(close-pipe port)" inside the "let" clause get executed?
> (It looks like a variable definition).

No, you are right, but I can do it like this (it is nice to have
open and close close to each other):

(define (readlink file)
  (let*
   (
    (port (open-input-pipe (string-append "readlink -f " file)))
    (str  (read-line port))
    (dummy (close-pipe port))
   )
   str
  )
)

but perhaps it is better doing this like:

(define (read1pipe cmd)
  (let*
   (
    (port (open-input-pipe cmd))
    (str  (read-line port))
   )
   (close-pipe port)
   str
  )
)

(define (readlink file) (read1pipe (string-append "readlink -f " file)))

Regards,
/Karl Hammar

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019