From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Adam Faiz Newsgroups: gmane.lisp.guile.devel Subject: Re: rdelim: Add new procedure `for-line-in-file`. Date: Mon, 16 Dec 2024 10:29:02 +0800 Message-ID: References: <68eef85f-611e-3245-fa5a-675dc3484def@disroot.org> <87ed28kho0.fsf@elephly.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24995"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel@gnu.org To: Ricardo Wurmus Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Mon Dec 16 03:29:51 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 1tN0rm-0006Jy-Nr for guile-devel@m.gmane-mx.org; Mon, 16 Dec 2024 03:29:50 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tN0rL-0003fJ-Jj; Sun, 15 Dec 2024 21:29:23 -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 1tN0rI-0003en-R0 for guile-devel@gnu.org; Sun, 15 Dec 2024 21:29:21 -0500 Original-Received: from layka.disroot.org ([178.21.23.139]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tN0rG-0004w2-OW for guile-devel@gnu.org; Sun, 15 Dec 2024 21:29:20 -0500 Original-Received: from mail01.disroot.lan (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 7588325257; Mon, 16 Dec 2024 03:29:16 +0100 (CET) X-Virus-Scanned: SPAM Filter at disroot.org Original-Received: from layka.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id yTuoVQYoAEnb; Mon, 16 Dec 2024 03:29:12 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1734316152; bh=/NRCA0YRSXnrreitKQr8MJbKen2F+d8FhNb2YKT1dHM=; h=Date:To:Cc:References:From:Subject:In-Reply-To; b=UqKV+mVdp5Upm9PQCYOShLmbbPBTo2/V5+UX3bUcyGQ+hB/GDpScKRAmnvgsfwQPq vjQ2i8Zk2Ev248N94JADDJcUP9O4VsLIqaCBPWluU5eKfh2y3ovu0u/cv5sey89D+q VydYl7FuwIHE/PANNTXMeC+8qABBG/GalmBIMyfSWV6XSGAWBibvOHAaGanSrQHN7g nUmMGaQOjfxTgIVLpnRMyaW6SMmfdsUPcPKa53nm/qPkvnYGIYLLyGyYKwJ/jJCegS UWcoMQpmrNfasFR8lWjazBgH1k/QcDIKhx8oqe9iwhtedCTEmLB/A9xpW/3dRs+WMI oawFr2QSkvIZA== Content-Language: en-US In-Reply-To: <87ed28kho0.fsf@elephly.net> Received-SPF: pass client-ip=178.21.23.139; envelope-from=adam.faiz@disroot.org; helo=layka.disroot.org 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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:22815 Archived-At: 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 >> 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