From: Adam Faiz <adam.faiz@disroot.org>
To: guile-devel@gnu.org
Subject: rdelim: Add new procedure `for-line-in-file`.
Date: Mon, 16 Dec 2024 00:00:01 +0800 [thread overview]
Message-ID: <68eef85f-611e-3245-fa5a-675dc3484def@disroot.org> (raw)
From 18485a2b94595ae2239f5dcdeb06d3a80bb04bf1 Mon Sep 17 00:00:00 2001
From: AwesomeAdam54321 <adam.faiz@disroot.org>
Date: Sun, 15 Dec 2024 23:48:30 +0800
Subject: [PATCH] rdelim: Add new procedure `for-line-in-file`.
* module/ice-9/rdelim.scm (for-line-in-file): Add it.
---
module/ice-9/rdelim.scm | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/module/ice-9/rdelim.scm b/module/ice-9/rdelim.scm
index d2cd081d7..ffa38efad 100644
--- a/module/ice-9/rdelim.scm
+++ b/module/ice-9/rdelim.scm
@@ -206,3 +206,15 @@ characters to read. By default, there is no limit."
line)
(else
(error "unexpected handle-delim value: " handle-delim)))))
+
+;;; for-line-in-file [PORT BODY] calls BODY (a procedure with the
+;;; line from PORT as it's argument) for every line until the
+;;; eof-object is reached. The line provided to BODY is guaranteed
+;;; to be a string.
+
+(define (for-line-in-file file body)
+ (while #t
+ (let ((line (read-line file)))
+ (if (string? line)
+ (body line)
+ (break)))))
--
2.41.0
next reply other threads:[~2024-12-15 16:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-15 16:00 Adam Faiz [this message]
2024-12-15 16:57 ` rdelim: Add new procedure `for-line-in-file` Ricardo Wurmus
2024-12-15 20:33 ` Maxime Devos
2024-12-16 2:29 ` Adam Faiz
2024-12-16 7:42 ` Ricardo Wurmus
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=68eef85f-611e-3245-fa5a-675dc3484def@disroot.org \
--to=adam.faiz@disroot.org \
--cc=guile-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.
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).