From: Nala Ginrut <nalaginrut@gmail.com>
To: Adam Faiz <adam.faiz@disroot.org>
Cc: guile-devel@gnu.org, Ricardo Wurmus <rekado@elephly.net>,
Tomas Volf <~@wolfsden.cz>, Maxime Devos <maximedevos@telenet.be>
Subject: Re: [PATCH 1/2] rdelim: Add new procedure `for-rdelim-in-port`.
Date: Tue, 17 Dec 2024 01:46:18 +0900 [thread overview]
Message-ID: <CAPjoZod7Q3sGmfuS+v8mO8gEzOKD9z8fCONcBrKoaK1ZY4DiOQ@mail.gmail.com> (raw)
In-Reply-To: <d6abae37-02d8-a7e0-e184-9db06159b975@disroot.org>
[-- Attachment #1: Type: text/plain, Size: 3284 bytes --]
Thanks for the work!
I didn’t find anything to be picky about yet in the implementation.
Now there are two things could go further.
1. About the port closing, I don’t insist on my previous suggestion right
now. There may be arguments against it by folks. I’m fine with any.
2. To complete a promising patch, it’s better to have test cases. You may
take a look at the existing tests to learn how.
Best regards.
On Reiwa 6 Dec 17, Tue at 0:22 Adam Faiz <adam.faiz@disroot.org> wrote:
> From 302159fe61d9df526911ead8ea6ad823ad8b0443 Mon Sep 17 00:00:00 2001
> From: AwesomeAdam54321 <adam.faiz@disroot.org>
> Date: Sun, 15 Dec 2024 23:48:30 +0800
> Subject: [PATCH 1/2] rdelim: Add new procedure `for-rdelim-in-port`.
>
> * module/ice-9/rdelim.scm (for-rdelim-in-port): Add it.
> (for-delimited-in-port): Define as a specialised `for-rdelim-in-port`.
> (for-line-in-file): Define as a specialised `for-delimited-in-port`.
>
> These procedures provide a backbone for parsing, with domain-specific
> logic implemented as a separate procedure to be passed as an argument.
> ---
> module/ice-9/rdelim.scm | 35 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 34 insertions(+), 1 deletion(-)
>
> diff --git a/module/ice-9/rdelim.scm b/module/ice-9/rdelim.scm
> index d2cd081d7..0bbaaf904 100644
> --- a/module/ice-9/rdelim.scm
> +++ b/module/ice-9/rdelim.scm
> @@ -23,7 +23,10 @@
> ;;; similar to (scsh rdelim) but somewhat incompatible.
>
> (define-module (ice-9 rdelim)
> - #:export (read-line
> + #:export (for-delimited-in-port
> + for-line-in-file
> + for-rdelim-in-port
> + read-line
> read-line!
> read-delimited
> read-delimited!
> @@ -206,3 +209,33 @@ characters to read. By default, there is no limit."
> line)
> (else
> (error "unexpected handle-delim value: " handle-delim)))))
> +
> +(define* (for-rdelim-in-port port proc rdelim-proc
> + #:key (stop-pred eof-object?))
> + "Call PROC for every (RDELIM-PROC PORT) in PORT until STOP-PRED returns
> #t.
> +RDELIM-PROC has to advance through PORT with every call."
> + (let loop ((rdelim (rdelim-proc port)))
> + (cond ((stop-pred rdelim)
> + (close-port port))
> + (else
> + (proc rdelim)
> + (loop (rdelim-proc port))))))
> +
> +(define* (for-delimited-in-port port proc
> + #:key (delims "\n") (handle-delim 'trim))
> + "Call PROC for every delimited line in PORT until the eof-object is
> reached."
> + (for-rdelim-in-port port proc
> + (lambda (port)
> + (read-delimited delims port handle-delim))))
> +
> +(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 must be a filename string.
> +
> +The line provided to PROC is guaranteed to be a string."
> + (call-with-input-file
> + file
> + (lambda (port)
> + (for-delimited-in-port port proc))
> + #:encoding encoding #:guess-encoding guess-encoding))
> --
> 2.41.0
>
[-- Attachment #2: Type: text/html, Size: 4231 bytes --]
prev parent reply other threads:[~2024-12-16 16:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 15:21 [PATCH 1/2] rdelim: Add new procedure `for-rdelim-in-port` Adam Faiz
2024-12-16 15:24 ` [PATCH 2/2] doc: Add documentation for `for-rdelim-in-port` and, related procedures Adam Faiz
2024-12-17 4:31 ` [PATCH] test-suite: Add tests for `for-rdelim-in-port`-related functions Adam Faiz
2024-12-17 5:11 ` Nala Ginrut
2024-12-17 7:21 ` Mikael Djurfeldt
2024-12-17 16:43 ` Mikael Djurfeldt
2024-12-16 16:46 ` Nala Ginrut [this message]
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=CAPjoZod7Q3sGmfuS+v8mO8gEzOKD9z8fCONcBrKoaK1ZY4DiOQ@mail.gmail.com \
--to=nalaginrut@gmail.com \
--cc=adam.faiz@disroot.org \
--cc=guile-devel@gnu.org \
--cc=maximedevos@telenet.be \
--cc=rekado@elephly.net \
--cc=~@wolfsden.cz \
/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).