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 AM Mikael Djurfeldt <mik...@djurfeldt.com>
wrote:

> Do others think this as well? To me, the shorter names which Adam selected
> seem more palatable. Otherwise they get a bit long.
>
> Den tis 17 dec. 2024 06:11Nala Ginrut <nalagin...@gmail.com> 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 should
>> be named as for-each-*-in-file, which is more understandable in the first
>> glance.
>> Best regards.
>>
>> On Tue, Dec 17, 2024, 13:31 Adam Faiz <adam.f...@disroot.org> wrote:
>>
>>> From 258d20a9665e6f845a167258c33374a00e734885 Mon Sep 17 00:00:00 2001
>>> From: AwesomeAdam54321 <adam.f...@disroot.org>
>>> 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
>>>
>>

Reply via email to