unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Ricardo Wurmus <rekado@elephly.net>
To: Adam Faiz <adam.faiz@disroot.org>
Cc: guile-devel@gnu.org,  Nala Ginrut <nalaginrut@gmail.com>,
	 Maxime Devos <maximedevos@telenet.be>
Subject: Re: [PATCH v3] rdelim: Add new procedure `for-line-in-file`.
Date: Mon, 16 Dec 2024 12:33:13 +0100	[thread overview]
Message-ID: <87a5cvj212.fsf@elephly.net> (raw)
In-Reply-To: <c68eaf83-c3f4-3829-6793-5627888b6863@disroot.org> (Adam Faiz's message of "Mon, 16 Dec 2024 16:43:44 +0800")

Adam Faiz <adam.faiz@disroot.org> writes:

> +(define* (for-line-in-file file proc
> +                           #:key (encoding #f) (guess-encoding #f))
> +  "Call PROC for every line in FILE until the eof-object is reached.
> +FILE can either be a filename string or an already opened input port.
> +The corresponding port is closed upon completion.
> +
> +The line provided to PROC is guaranteed to be a string."
> +  (let ((port
> +         (if (input-port? file)
> +             file
> +             (open-input-file file
> +                              #:encoding encoding
> +                              #:guess-encoding guess-encoding))))
> +    (let loop ((line (read-line port)))
> +      (cond ((eof-object? line)
> +             (close-port port))
> +            (else
> +             (proc line)
> +             (loop (read-line port)))))))

I think the port would leak if PROC were to raise an exception.

-- 
Ricardo



  parent reply	other threads:[~2024-12-16 11:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16  8:43 [PATCH v3] rdelim: Add new procedure `for-line-in-file` Adam Faiz
2024-12-16 11:27 ` Tomas Volf
2024-12-16 13:08   ` Nala Ginrut
2024-12-16 11:33 ` Ricardo Wurmus [this message]
2024-12-16 12:18   ` Maxime Devos

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://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=87a5cvj212.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=adam.faiz@disroot.org \
    --cc=guile-devel@gnu.org \
    --cc=maximedevos@telenet.be \
    --cc=nalaginrut@gmail.com \
    /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.
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).