From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] test-suite: Add tests for `for-rdelim-in-port`-related functions. Date: Tue, 17 Dec 2024 17:43:02 +0100 Message-ID: References: <43ad0b39-03cf-b648-3bc9-8c4a064519a8@disroot.org> <8e113f49-c1dc-313b-e65a-24a73c5b887a@disroot.org> Reply-To: mikael@djurfeldt.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000004389ad062979fe05" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28075"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Adam Faiz , guile-devel , Ricardo Wurmus , Tomas Volf <~@wolfsden.cz>, Maxime Devos To: Nala Ginrut Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Tue Dec 17 17:43: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 1tNafg-00077l-T7 for guile-devel@m.gmane-mx.org; Tue, 17 Dec 2024 17:43:45 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNafG-00025j-1L; Tue, 17 Dec 2024 11:43:19 -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 1tNafF-00025a-4E for guile-devel@gnu.org; Tue, 17 Dec 2024 11:43:17 -0500 Original-Received: from mail-vs1-f50.google.com ([209.85.217.50]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tNafD-0001XK-0M for guile-devel@gnu.org; Tue, 17 Dec 2024 11:43:16 -0500 Original-Received: by mail-vs1-f50.google.com with SMTP id ada2fe7eead31-4afdd15db60so1415707137.1 for ; Tue, 17 Dec 2024 08:43:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734453794; x=1735058594; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=abzs4s7jFWPcjUo950phQvMUqx/GrZxtQOgQ7CFHwNs=; b=tRzG3pboUUtsC0r89ZzCmSTYXwey3w9zifAp8ePiQ4OZea4SQ/5zzyOiZrwg1ONlyG X3amBZ5yWFmERGWWUXIzaLn+C/pGgjyazbSAuFzY+qboOsiEv7CMU3PrA6jTbzSIArkI N0caipsqujUW2QxPefGdw9bOJgLIBi6nZB2xQ16wJWhcvHjOemsVmTpCmzrTR4VlLGRL 3GOEu0JWlgIWOpS2pO2buDmTgu6Cc4v7PQLTyi4PKioCwjILZsrwFbPflS1JtsYtadrH CPZMotTGW7zu+t09dQob9iZujGu9p0pmaN0+e65YS8LR5VJgnhXr08vDuEd4GuQky+Hr Ta0Q== X-Forwarded-Encrypted: i=1; AJvYcCUnLNwSqaGF/HIdoihURaAHKK53/YB6CBdsg4pRuejpwCw67N1HXpP6pqzBctsxT7o1UbRPYZP9k3Si+A==@gnu.org X-Gm-Message-State: AOJu0Yxl/S/fVPGeZuhgwOcLqKZNkKhOMxbrAGc+JnlU/C7ULwYvq771 eBYPUkIyIRarX91FMhzPLeHhGQKeVO8kEz/WGfxK6jz14m69D95uPuCYvIGCkwJKWaNTC4J+V4y poRRldx7rWXQ2Lbfkou02MJgSPZQ= X-Gm-Gg: ASbGncv4VtxAt2txsBQVjgfBLvkSE0E8oesfmZJSR/9TAxkrhS3HqDGXMwulDcPtrYN ubL+T25hgbCCArhOehSQjQY9eKBMZKJzPjExw7jg= X-Google-Smtp-Source: AGHT+IFSbmp5WixIOQoss7nJ/TPoOJo6GhURQTpMMqH8F8cmSoy5LzCwhF9d+3F3WdKvB1wEPn/SPrm8yIcQC/xPPt4= X-Received: by 2002:a05:6102:b10:b0:4b2:5c0a:9afa with SMTP id ada2fe7eead31-4b29c9e625dmr4124858137.4.1734453793881; Tue, 17 Dec 2024 08:43:13 -0800 (PST) In-Reply-To: Received-SPF: pass client-ip=209.85.217.50; envelope-from=mdjurfeldt@gmail.com; helo=mail-vs1-f50.google.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.248, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1.116, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, 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:22838 Archived-At: --0000000000004389ad062979fe05 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable I think these procedures are handy in common situations. There has been a discussion about generalization. I have the feeling that such generalization either already exists in some SRFI or that one should put some deep thinking into how to represent flexible iteration in Scheme. I don't think it would be bad to apply Adam's patch, though, or that placing it in (ice-9 rdelim) is unnatural. If no one objects, I will apply the patch in a couple of days with the current naming scheme but modified by the following: I think "in-port" is redundant and slightly confusing and ambiguous (c.f. "input") and would replace it with "from-port" to conform with other procedure names (such as with-input-from-port). On the other hand, "line-in-file" feels natural despite the existence of with-input-from-file. On Tue, Dec 17, 2024 at 8:21=E2=80=AFAM Mikael Djurfeldt wrote: > Do others think this as well? To me, the shorter names which Adam selecte= d > seem more palatable. Otherwise they get a bit long. > > Den tis 17 dec. 2024 06:11Nala Ginrut skrev: > >> The preferred activity in your design is more like for-each family, say, >> handle the result inside the proc without return result. So maybe it sho= uld >> be named as for-each-*-in-file, which is more understandable in the firs= t >> glance. >> Best regards. >> >> On Tue, Dec 17, 2024, 13:31 Adam Faiz wrote: >> >>> From 258d20a9665e6f845a167258c33374a00e734885 Mon Sep 17 00:00:00 2001 >>> From: AwesomeAdam54321 >>> Date: Tue, 17 Dec 2024 12:20:52 +0800 >>> Subject: [PATCH] test-suite: Add tests for `for-rdelim-in-port`-related >>> functions. >>> >>> * test-suite/tests/ports.test: Add test cases for >>> `for-delimited-in-port` and `for-line-in-file`. >>> --- >>> test-suite/tests/ports.test | 22 ++++++++++++++++++++++ >>> 1 file changed, 22 insertions(+) >>> >>> diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test >>> index bec5e356c..15d515f1f 100644 >>> --- a/test-suite/tests/ports.test >>> +++ b/test-suite/tests/ports.test >>> @@ -2089,6 +2089,28 @@ >>> (not (string-index (%search-load-path (basename (test-file))= ) >>> #\\)))))) >>> >>> +(let ((lst '()) >>> + (lines '()) >>> + (string "line1\nline2\nline3") >>> + (filename (test-file))) >>> + (call-with-input-string >>> + "A\0B\0C" >>> + (lambda (port) >>> + (pass-if "for-delimited-in-port returns true upon completion" >>> + (for-delimited-in-port port >>> + (lambda (entry) >>> + (set! lst (cons entry lst))) >>> + #:delims "\0") >>> + (equal? lst '("C" "B" "A"))))) >>> + (let ((port (open-output-file filename))) >>> + (display string port) >>> + (close-port port)) >>> + (pass-if "for-line-in-file returns true upon completion" >>> + (for-line-in-file filename >>> + (lambda (line) >>> + (set! lines (cons line lines)))) >>> + (equal? lines '("line3" "line2" "line1")))) >>> + >>> (delete-file (test-file)) >>> >>> ;;; Local Variables: >>> -- >>> 2.46.0 >>> >> --0000000000004389ad062979fe05 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think these procedures are handy in common situatio= ns. There has been a discussion about generalization. I have the feeling th= at such generalization either already exists in some SRFI or that one shoul= d put some deep thinking into how to represent flexible iteration in Scheme= .

I don't think it would be bad to apply Adam&= #39;s patch, though, or that placing it in (ice-9 rdelim) is unnatural.

If no one objects, I will apply the patch in a couple= of days with the current naming scheme but modified by the following:

I think "in-port" is redundant and slightly = confusing and ambiguous (c.f. "input") and would replace it with = "from-port" to conform with other procedure names (such as with-i= nput-from-port). On the other hand, "line-in-file" feels natural = despite the existence of with-input-from-file.

On Tue, Dec 17, 2024 at 8:21=E2=80=AFAM Mikael Djurfeldt <mikael@djurfeldt.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
Do other= s think this as well? To me, the shorter names which Adam selected seem mor= e palatable. Otherwise they get a bit long.

Den tis 17 dec. 2024 06:11Nala G= inrut <nalagin= rut@gmail.com> skrev:

The preferred activity in your design is more l= ike for-each family, say, handle the result inside the proc without return = result. So maybe it should be named as for-each-*-in-file, which is more un= derstandable in the first glance.

Best regards.

On Tue, Dec 17, 2024, 13:31 Adam Faiz <adam.faiz@di= sroot.org> wrote:
From 258d20a9665e6f845a167258c33374a00e734885 Mon Sep 17 00:00:0= 0 2001
From: AwesomeAdam54321 <adam.faiz@disroot.org>
Date: Tue, 17 Dec 2024 12:20:52 +0800
Subject: [PATCH] test-suite: Add tests for `for-rdelim-in-port`-related
=C2=A0functions.

* test-suite/tests/ports.test: Add test cases for
`for-delimited-in-port` and `for-line-in-file`.
---
=C2=A0test-suite/tests/ports.test | 22 ++++++++++++++++++++++
=C2=A01 file changed, 22 insertions(+)

diff --git a/test-suite/tests/ports.test b/test-suite/tests/ports.test
index bec5e356c..15d515f1f 100644
--- a/test-suite/tests/ports.test
+++ b/test-suite/tests/ports.test
@@ -2089,6 +2089,28 @@
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(not (string-index (%search-load-p= ath (basename (test-file)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 #\\))))))

+(let ((lst '())
+=C2=A0 =C2=A0 =C2=A0 (lines '())
+=C2=A0 =C2=A0 =C2=A0 (string "line1\nline2\nline3")
+=C2=A0 =C2=A0 =C2=A0 (filename (test-file)))
+=C2=A0 (call-with-input-string
+=C2=A0 =C2=A0 =C2=A0 "A\0B\0C"
+=C2=A0 =C2=A0 (lambda (port)
+=C2=A0 =C2=A0 =C2=A0 (pass-if "for-delimited-in-port returns true upo= n completion"
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (for-delimited-in-port port
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(lambda (entry)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(set! lst (cons entry lst))) +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0#:delims "\0")
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 (equal? lst '("C" "B" = "A")))))
+=C2=A0 (let ((port (open-output-file filename)))
+=C2=A0 =C2=A0 (display string port)
+=C2=A0 =C2=A0 (close-port port))
+=C2=A0 (pass-if "for-line-in-file returns true upon completion"<= br> +=C2=A0 =C2=A0 (for-line-in-file filename
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 (lambda (line)
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 (set! lines (cons line lines))))
+=C2=A0 =C2=A0 (equal? lines '("line3" "line2" &quo= t;line1"))))
+
=C2=A0(delete-file (test-file))

=C2=A0;;; Local Variables:
--
2.46.0
--0000000000004389ad062979fe05--