unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* rdelim: Add new procedure `for-line-in-file`.
@ 2024-12-15 16:00 Adam Faiz
  2024-12-15 16:57 ` Ricardo Wurmus
  0 siblings, 1 reply; 5+ messages in thread
From: Adam Faiz @ 2024-12-15 16:00 UTC (permalink / raw)
  To: guile-devel

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



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: rdelim: Add new procedure `for-line-in-file`.
  2024-12-15 16:00 rdelim: Add new procedure `for-line-in-file` Adam Faiz
@ 2024-12-15 16:57 ` Ricardo Wurmus
  2024-12-15 20:33   ` Maxime Devos
  2024-12-16  2:29   ` Adam Faiz
  0 siblings, 2 replies; 5+ messages in thread
From: Ricardo Wurmus @ 2024-12-15 16:57 UTC (permalink / raw)
  To: Adam Faiz; +Cc: guile-devel

Hi Adam,

has this patch been discussed somewhere else?  I'm asking because I have
no context other than this patch.

> 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)))))

It is preferrable to use a docstring instead of a comment.  The choice
of argument names is inconsistent, though.  You're using PORT in the
comment and FILE in the definition.  BODY as a name for a procedure is
also a rather "inspired" choice.

Where is BREAK defined?

-- 
Ricardo



^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: rdelim: Add new procedure `for-line-in-file`.
  2024-12-15 16:57 ` Ricardo Wurmus
@ 2024-12-15 20:33   ` Maxime Devos
  2024-12-16  2:29   ` Adam Faiz
  1 sibling, 0 replies; 5+ messages in thread
From: Maxime Devos @ 2024-12-15 20:33 UTC (permalink / raw)
  To: Ricardo Wurmus, Adam Faiz; +Cc: guile-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 130 bytes --]

>Where is BREAK defined?

Break is defined by ‘while’: https://www.gnu.org/software/guile/manual/html_node/while-do.html


[-- Attachment #2: Type: text/html, Size: 1409 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: rdelim: Add new procedure `for-line-in-file`.
  2024-12-15 16:57 ` Ricardo Wurmus
  2024-12-15 20:33   ` Maxime Devos
@ 2024-12-16  2:29   ` Adam Faiz
  2024-12-16  7:42     ` Ricardo Wurmus
  1 sibling, 1 reply; 5+ messages in thread
From: Adam Faiz @ 2024-12-16  2:29 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guile-devel

Hi Ricardo,

On 12/16/24 00:57, Ricardo Wurmus wrote:
> Hi Adam,
> 
> has this patch been discussed somewhere else?  I'm asking because I have
> no context other than this patch.

No, actually. Was I supposed to discuss it's use in the patch cover letter?

The reason I sent this patch was to make it convenient for other Scheme
programmers to do per-line processing of a text file, if they need to do so.

>> 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)))))


> It is preferrable to use a docstring instead of a comment.  The choice
> of argument names is inconsistent, though.  You're using PORT in the
> comment and FILE in the definition.  BODY as a name for a procedure is
> also a rather "inspired" choice.

Thanks for the feedback! I'll send a revised patch that addresses these issues.
 
> Where is BREAK defined?

Break is defined by the ‘while’ loop:
https://www.gnu.org/software/guile/manual/html_node/while-do.html




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: rdelim: Add new procedure `for-line-in-file`.
  2024-12-16  2:29   ` Adam Faiz
@ 2024-12-16  7:42     ` Ricardo Wurmus
  0 siblings, 0 replies; 5+ messages in thread
From: Ricardo Wurmus @ 2024-12-16  7:42 UTC (permalink / raw)
  To: Adam Faiz; +Cc: guile-devel

Hi Adam,

> On 12/16/24 00:57, Ricardo Wurmus wrote:
>> Hi Adam,
>> 
>> has this patch been discussed somewhere else?  I'm asking because I have
>> no context other than this patch.
>
> No, actually. Was I supposed to discuss it's use in the patch cover letter?

No, there is no requirement to do so.  I just wanted to make sure I'm
not bothering you by poking at things that had previously been agreed
upon with other developers.

Explaining the patch in the preamble / commit message would be a good
idea for future patches, though.

>> Where is BREAK defined?
>
> Break is defined by the ‘while’ loop:
> https://www.gnu.org/software/guile/manual/html_node/while-do.html

Ah, right, I missed it.  Thanks!

-- 
Ricardo



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-16  7:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-15 16:00 rdelim: Add new procedure `for-line-in-file` Adam Faiz
2024-12-15 16:57 ` Ricardo Wurmus
2024-12-15 20:33   ` Maxime Devos
2024-12-16  2:29   ` Adam Faiz
2024-12-16  7:42     ` Ricardo Wurmus

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).