From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ricardo Wurmus Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH v3] rdelim: Add new procedure `for-line-in-file`. Date: Mon, 16 Dec 2024 12:33:13 +0100 Message-ID: <87a5cvj212.fsf@elephly.net> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22578"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.12.7; emacs 29.4 Cc: guile-devel@gnu.org, Nala Ginrut , Maxime Devos To: Adam Faiz Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Mon Dec 16 12:34:00 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 1tN9MN-0005gZ-Eq for guile-devel@m.gmane-mx.org; Mon, 16 Dec 2024 12:33:59 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tN9Lx-00015b-0Z; Mon, 16 Dec 2024 06:33:33 -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 1tN9Lu-00015G-LM for guile-devel@gnu.org; Mon, 16 Dec 2024 06:33:30 -0500 Original-Received: from sender4-of-o51.zoho.com ([136.143.188.51]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tN9Ls-0002OT-S5 for guile-devel@gnu.org; Mon, 16 Dec 2024 06:33:30 -0500 ARC-Seal: i=1; a=rsa-sha256; t=1734348805; cv=none; d=zohomail.com; s=zohoarc; b=C3va+hUy+7vbS1nxBs22Zhaza9hjqAYdmhOT55BBFRg6tj/fozAo3XTVnebyOYB4x8kr85MBEugKG47VeLkLdnmjSqzEenlhT0pKtwTuQZAFXRMfbDSJgAVuzqq/EbTtMMczC+ofuwGSjL+VOTDI0jUT1eWfV7QYLUhminEdHoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1734348805; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=DGbj0MlpuC5QTjZppIN62LsOuU/3hyPbNliguTY2c5w=; b=fTvNcer+UlFi8A3ftJSv++ahtraJtsjj8M6paj32fM10Yt4ptJ4gnqmwdDbyk8V32/5GQi+Z8t9zy4MSkGcZSFuzTzfXMqsxod34laXFOB/OHvsEmXjmVd7Zi6RwJ5i19waZmNtvIDTICntxqGqzX9vmMvqb/bV7S0laYANzDf4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=elephly.net; spf=pass smtp.mailfrom=rekado@elephly.net; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1734348805; s=zoho; d=elephly.net; i=rekado@elephly.net; h=From:From:To:To:Cc:Cc:Subject:Subject:In-Reply-To:References:Date:Date:Message-ID:MIME-Version:Content-Type:Message-Id:Reply-To; bh=DGbj0MlpuC5QTjZppIN62LsOuU/3hyPbNliguTY2c5w=; b=Y9Dhv0UUH/E7oyBWA46/rNaxpBaEkfbBMc/nMph0Exrw59IQu/Z6obyA8OMdnzQT he+BvjqnKIT5/uSCj/wDHiISWJbIlybUHL/4AAGkfvuhkDSEoUrz5DW3/EmAVLvgALm h4OpIlgT7sAM/fwQL755CVQuJTCJSFQELT3FtIw8= Original-Received: by mx.zohomail.com with SMTPS id 173434880311145.94074339844292; Mon, 16 Dec 2024 03:33:23 -0800 (PST) In-Reply-To: (Adam Faiz's message of "Mon, 16 Dec 2024 16:43:44 +0800") X-ZohoMailClient: External Received-SPF: pass client-ip=136.143.188.51; envelope-from=rekado@elephly.net; helo=sender4-of-o51.zoho.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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, 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:22827 Archived-At: Adam Faiz writes: > +(define* (for-line-in-file file proc > + #:key (encoding #f) (guess-encoding #f)) > + "Call PROC for every line in FILE until the eof-object is reached. > +FILE can either be a filename string or an already opened input port. > +The corresponding port is closed upon completion. > + > +The line provided to PROC is guaranteed to be a string." > + (let ((port > + (if (input-port? file) > + file > + (open-input-file file > + #:encoding encoding > + #:guess-encoding guess-encoding)))) > + (let loop ((line (read-line port))) > + (cond ((eof-object? line) > + (close-port port)) > + (else > + (proc line) > + (loop (read-line port))))))) I think the port would leak if PROC were to raise an exception. -- Ricardo