From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Nala Ginrut Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH v1] rdelim: Add new procedure `for-line-in-file`. Date: Mon, 16 Dec 2024 12:55:11 +0900 Message-ID: References: <7e7993ce-f238-fd3f-393b-7eeeec526bfc@disroot.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="00000000000065574806295b26b1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34105"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel@gnu.org, Ricardo Wurmus , Maxime Devos To: Adam Faiz Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Mon Dec 16 04:55:45 2024 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tN2Cu-0008i9-Rn for guile-devel@m.gmane-mx.org; Mon, 16 Dec 2024 04:55:44 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tN2Ce-0004gu-Jk; Sun, 15 Dec 2024 22:55:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tN2Cd-0004gf-1M for guile-devel@gnu.org; Sun, 15 Dec 2024 22:55:27 -0500 Original-Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tN2Cb-0006Mx-3k for guile-devel@gnu.org; Sun, 15 Dec 2024 22:55:26 -0500 Original-Received: by mail-pj1-x102b.google.com with SMTP id 98e67ed59e1d1-2ee397a82f6so3169854a91.2 for ; Sun, 15 Dec 2024 19:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734321323; x=1734926123; darn=gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=hjCXeio11vIi12cLrpsIeZSfTRpc7fYlIHEnG986wbY=; b=Q+8LaNnviqWH8Xv2Krim7Ek9UpzZhiKhoAlOtl/04mLaS+VFSNiCfuYXZXOZjihlfC 8EYLtazpivIz/+L8/kXuUro6ZeD/V6WYpe93p+UI8sIHt6ota1u+uvFmE+f2djsdT728 Isho6WXAg7Qo1+fMVD3BzD70EXlu5MDVO9z+inDVMcBCE4qDmzSDbsSiO8SHKoIkbRZj DBZbz0pdNI4uxZAfnGJlwvj2KDQ6acLbyCqsRvJT22sc92tHl5OFANCYYvKWfN0lqrwx rlupx9BQQGO4SJ86I5421uiX3V1icXiokYqEo9xgJo82t1Ho9A9jqz2fDNprfBoa1is3 BiWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734321323; x=1734926123; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=hjCXeio11vIi12cLrpsIeZSfTRpc7fYlIHEnG986wbY=; b=IqvGYdyHW9c01WRviYNbrPDLzA44BUi5ohRm12Ig6eYAIa3JglDiqrBLUyrEC8Jwdd mxEnxHmuYYbeKgGdPT4l03Tf2AaByDwZTjZLnJxp7sHmkNwNHXQifYI8/7s6E+MM2c0+ sthmDOoLXHPHX4L67fMubwonHcJZ10eruu862bdzSJ5e3Pm+XuMCNyy4BfIuyKX20BcY pz/M4O2xX7UT5vm352OJ7AiKWsYOz3e8s8Ee4UBSxRWpsKqcVgWJnUSmXjlxmpqJxhQD DqXVjTJe+YmUSZZqq9u1HStViR4OGeuez1vjJlNrX3MoBp53BkTiFXocA/cj5cXGxyJR QiMA== X-Gm-Message-State: AOJu0Yx0vDUCv3joOqMBz8XaH5srQ9qRYL4yrUE7kSQoYRgXUnMid1TB k5MRJgkoTMfaipMoY/KRGeSD2YsYyuYn6dmNdO9KnwsDCMp6SVMFmZTo5YghW+N1zAnHm9Unxc9 f1xzlBTRUxkq7PN8ZQWxDI68ddxJc/g== X-Gm-Gg: ASbGncvgSHDYVT4s00Psh0h22b2Dlct3FZno+pnW1KNC04p4MYJWI/cNQ4hgDl6PPGw hzp6ixhExAKD/G0zgJeJP/RYhuBOlx2fzfTB7gvNoFPxfhvmr/oS02nkLzduQNJFiUVnzMA== X-Google-Smtp-Source: AGHT+IGRnq0AjG00zERI+7KOi7Ss5nVLVol2/oouk6nD0pF0D89xqQeL7rCHmdpge24XfzeLLWa+x0fN81zuZNfu6KQ= X-Received: by 2002:a17:90b:5488:b0:2f2:a664:df20 with SMTP id 98e67ed59e1d1-2f2a664e192mr9631198a91.7.1734321323200; Sun, 15 Dec 2024 19:55:23 -0800 (PST) In-Reply-To: <7e7993ce-f238-fd3f-393b-7eeeec526bfc@disroot.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=nalaginrut@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.devel:22817 Archived-At: --00000000000065574806295b26b1 Content-Type: text/plain; charset="UTF-8" Hi Adam! I was confused with the name "file" here since it acts more like a port rather than a filename. If it's expected to be a opened port passed from the caller, it's better rename to "port". In your context, I think you want to check if it's the end of file, so you may use eof-object? To make your patch more useful, IMHO, you may support filename string and file port both. And close the port properly when it's end. Best regards. On Mon, Dec 16, 2024, 12:06 Adam Faiz wrote: > From 3c7e1af1f4812d0e4c5d10e841cf9546e5ba2887 Mon Sep 17 00:00:00 2001 > From: AwesomeAdam54321 > Date: Sun, 15 Dec 2024 23:48:30 +0800 > Subject: [PATCH v1] rdelim: Add new procedure `for-line-in-file`. > > * module/ice-9/rdelim.scm (for-line-in-file): Add it. > > This procedure makes it convenient to do per-line processing of a text > file. > --- > module/ice-9/rdelim.scm | 12 +++++++++++- > 1 file changed, 11 insertions(+), 1 deletion(-) > > diff --git a/module/ice-9/rdelim.scm b/module/ice-9/rdelim.scm > index d2cd081d7..833639219 100644 > --- a/module/ice-9/rdelim.scm > +++ b/module/ice-9/rdelim.scm > @@ -23,7 +23,8 @@ > ;;; similar to (scsh rdelim) but somewhat incompatible. > > (define-module (ice-9 rdelim) > - #:export (read-line > + #:export (for-line-in-file > + read-line > read-line! > read-delimited > read-delimited! > @@ -206,3 +207,12 @@ characters to read. By default, there is no limit." > line) > (else > (error "unexpected handle-delim value: " handle-delim))))) > + > +(define (for-line-in-file file proc) > + "Call PROC for every line in FILE until the eof-object is reached. > +The line provided to PROC is guaranteed to be a string." > + (while #t > + (let ((line (read-line file))) > + (if (string? line) > + (proc line) > + (break))))) > -- > 2.41.0 > > --00000000000065574806295b26b1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Adam!
I was confused with the name "file" here since it acts more like = a port rather than a filename. If it's expected to be a opened port pas= sed from the caller, it's better rename to "port".

In your context, I think you want to check if it's the e= nd of file, so you may use eof-object?

To make your patch more useful, IMHO, you may support filena= me string and file port both.=C2=A0 And close the port properly when it'= ;s end.

Best regards.

On Mon, Dec 16, 2024, 12:06 Adam Faiz <adam.faiz@disroot.org> wrote:
From 3c7e1af1f4812d0e4c5d10e841cf9546e5ba2887 Mon Sep 17 00:0= 0:00 2001
From: AwesomeAdam54321 <adam.faiz@disroot.org>
Date: Sun, 15 Dec 2024 23:48:30 +0800
Subject: [PATCH v1] rdelim: Add new procedure `for-line-in-file`.

* module/ice-9/rdelim.scm (for-line-in-file): Add it.

This procedure makes it convenient to do per-line processing of a text
file.
---
=C2=A0module/ice-9/rdelim.scm | 12 +++++++++++-
=C2=A01 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/module/ice-9/rdelim.scm b/module/ice-9/rdelim.scm
index d2cd081d7..833639219 100644
--- a/module/ice-9/rdelim.scm
+++ b/module/ice-9/rdelim.scm
@@ -23,7 +23,8 @@
=C2=A0;;; similar to (scsh rdelim) but somewhat incompatible.

=C2=A0(define-module (ice-9 rdelim)
-=C2=A0 #:export (read-line
+=C2=A0 #:export (for-line-in-file
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 read-line
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read-line!
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read-delimited
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0read-delimited!
@@ -206,3 +207,12 @@ characters to read.=C2=A0 By default, there is no limi= t."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 line)
=C2=A0 =C2=A0 =C2=A0 =C2=A0(else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (error "unexpected handle-delim value: &qu= ot; handle-delim)))))
+
+(define (for-line-in-file file proc)
+=C2=A0 "Call PROC for every line in FILE until the eof-object is reac= hed.
+The line provided to PROC is guaranteed to be a string."
+=C2=A0 (while #t
+=C2=A0 =C2=A0 (let ((line (read-line file)))
+=C2=A0 =C2=A0 =C2=A0 (if (string? line)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (proc line)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (break)))))
--
2.41.0

--00000000000065574806295b26b1--