From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: RE: [PATCH v3] rdelim: Add new procedure `for-line-in-file`. Date: Mon, 16 Dec 2024 13:18:45 +0100 Message-ID: <20241216131845.pQJl2D0051dDhme01QJlpW@laurent.telenet-ops.be> References: <87a5cvj212.fsf@elephly.net> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="_26B5C253-2FA6-4305-8A60-1F00A3A139D6_" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7747"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "guile-devel@gnu.org" , Nala Ginrut To: Ricardo Wurmus , Adam Faiz Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Mon Dec 16 13:19:34 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 1tNA4U-0001pd-2B for guile-devel@m.gmane-mx.org; Mon, 16 Dec 2024 13:19:34 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tNA45-0002q3-GL; Mon, 16 Dec 2024 07:19:11 -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 1tNA3y-0002pX-3t for guile-devel@gnu.org; Mon, 16 Dec 2024 07:19:03 -0500 Original-Received: from laurent.telenet-ops.be ([2a02:1800:110:4::f00:19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tNA3u-00006t-JS for guile-devel@gnu.org; Mon, 16 Dec 2024 07:19:01 -0500 Original-Received: from [IPv6:2a02:1811:8c0e:ef00:2ca3:f220:8d70:df09] ([IPv6:2a02:1811:8c0e:ef00:2ca3:f220:8d70:df09]) by laurent.telenet-ops.be with cmsmtp id pQJl2D0051dDhme01QJlpW; Mon, 16 Dec 2024 13:18:45 +0100 Importance: normal X-Priority: 3 In-Reply-To: <87a5cvj212.fsf@elephly.net> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r24; t=1734351525; bh=KXw0pMSqUTsX+MsO/s8Co5P+4qi0n+iBfSspUwKHoTo=; h=Message-ID:MIME-Version:To:Cc:From:Subject:Date:In-Reply-To: References:Content-Type:From; b=lKuwBrEqXbBELe39/Cz+lkZPZlxM8MdhtdKowNe1y7VdjN/slqU3fqjogFmEXBZju XyZZ2nm+XKTcCb3t2PxRpB4fyfNfkTImxbAdtaBASKzqvFi0tzU7/BoJqLViVVsQ6U n4+9a9f5trpaC+lhGd54grwaAz28fx4f1HmpeXPFJ3nBuQ+V2cHqSL6H+bP9Pkx+R9 QOg1h7DpVz/noRMyrRkdC2y2jnJjo7KPXeAmZ5Lt9tVF/SANpAEPteLRkYQOvK41Y2 W7EgRVgFImABj4oK9qF0MCpjt+gzckcOu6hj9LNjR4rq0b0fY9JPn9PfUjljfd+HIt t2B01Rh0PQLmA== Received-SPF: pass client-ip=2a02:1800:110:4::f00:19; envelope-from=maximedevos@telenet.be; helo=laurent.telenet-ops.be 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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:22829 Archived-At: --_26B5C253-2FA6-4305-8A60-1F00A3A139D6_ Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" >I think the port would leak if PROC were to raise an exception. To my knowledge, this is currently kind of impossible to properly handle, s= ince Scheme doesn=E2=80=99t have =E2=80=98finally=E2=80=99. Closest thing i= s =E2=80=98dynamic-wind=E2=80=99 + close it in the =E2=80=98out-guard=E2=80= =99, but that isn=E2=80=99t quite right since (re)winding can happen becaus= e of scheduling (e.g. Fibers) or other reasons other than exceptions, in wh= ich case it shouldn=E2=80=99t be closed. A potential other option is to implement =E2=80=98finally=E2=80=99 in terms= of exception handling, but even in case of exceptions, sometimes it should= n=E2=80=99t be closed =E2=80=93 if it is continuable and it is continued, t= hen the port shouldn=E2=80=99t be closed. I think the solution to this, is to make dynamic-wind overridable =E2=80=93= the current dynamic-wind would be renamed to primitive-dynamic-wind, dynam= ic-wind would default to primitive-dynamic-wind but could be overriden (may= be with a parameter), and userspace scheduler libraries can override =E2=80= =98dynamic-wind=E2=80=99 such that the =E2=80=98in-guard=E2=80=99 & =E2=80= =98out-guard=E2=80=99 is _not_ run when the (re)winding is because of sched= uling purposes.=20 Then, if the user needs a dynamic-wind for things like implementing paramet= er-like things (e.g. adjust a C thread-local variable with a similar API li= ke parameters), it would use primitive-dynamic-wind, and if it needs a dyna= mic-wind for things like resource cleanup, it would use =E2=80=98dynamic-wi= nd=E2=80=99. While not quite integrated in Guile like this yet, for practical implementa= tion see: =E2=80=A2 https://github.com/wingo/fibers/commit/cc0e84cd56df3b07d378f710df= 39f8822317a2a2 =E2=80=A2 https://git.sr.ht/~old/guile-parallel/tree/master/item/parallel.s= cm#L29 =E2=80=A2 (what=E2=80=99s missing here, is a way to override Guile=E2=80=99= s dynamic-wind in a transparent manner) Best regards, Maxime Devos --_26B5C253-2FA6-4305-8A60-1F00A3A139D6_ Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="utf-8"

>I think the port would leak if PROC were to raise an exce= ption.

&n= bsp;

To my knowledg= e, this is currently kind of impossible to properly handle, since Scheme do= esn=E2=80=99t have =E2=80=98finally=E2=80=99. Closest thing is =E2=80=98dyn= amic-wind=E2=80=99 + close it in the =E2=80=98out-guard=E2=80=99, but that = isn=E2=80=99t quite right since (re)winding can happen because of schedulin= g (e.g. Fibers) or other reasons other than exceptions, in which case it sh= ouldn=E2=80=99t be closed.

 

A potential other option is to implement =E2=80=98finally=E2=80=99 in= terms of exception handling, but even in case of exceptions, sometimes it = shouldn=E2=80=99t be closed =E2=80=93 if it is continuable and it is contin= ued, then the port shouldn=E2=80=99t be closed.

 

I think the solution to this, is to make dynamic= -wind overridable =E2=80=93 the current dynamic-wind would be renamed to pr= imitive-dynamic-wind, dynamic-wind would default to primitive-dynamic-wind = but could be overriden (maybe with a parameter), and userspace scheduler li= braries can override =E2=80=98dynamic-wind=E2=80=99 such that the =E2=80=98= in-guard=E2=80=99 & =E2=80=98out-guard=E2=80=99 is _not_ run whe= n the (re)winding is because of scheduling purposes.

=

 

Then, if the user needs a dynamic-wind for= things like implementing parameter-like things (e.g. adjust a C thread-loc= al variable with a similar API like parameters), it would use primitive-dyn= amic-wind, and if it needs a dynamic-wind for things like resource cleanup,= it would use =E2=80=98dynamic-wind=E2=80=99.

 

While not quite integrated in Guile like this yet,= for practical implementation see: