unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Maxime Devos <maximedevos@telenet.be>
To: Ricardo Wurmus <rekado@elephly.net>, Adam Faiz <adam.faiz@disroot.org>
Cc: "guile-devel@gnu.org" <guile-devel@gnu.org>,
	 Nala Ginrut <nalaginrut@gmail.com>
Subject: RE: [PATCH v3] rdelim: Add new procedure `for-line-in-file`.
Date: Mon, 16 Dec 2024 13:18:45 +0100	[thread overview]
Message-ID: <20241216131845.pQJl2D0051dDhme01QJlpW@laurent.telenet-ops.be> (raw)
In-Reply-To: <87a5cvj212.fsf@elephly.net>

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

>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, since Scheme doesn’t have ‘finally’. Closest thing is ‘dynamic-wind’ + close it in the ‘out-guard’, but that isn’t quite right since (re)winding can happen because of scheduling (e.g. Fibers) or other reasons other than exceptions, in which case it shouldn’t be closed.

A potential other option is to implement ‘finally’ in terms of exception handling, but even in case of exceptions, sometimes it shouldn’t be closed – if it is continuable and it is continued, then the port shouldn’t be closed.

I think the solution to this, is to make dynamic-wind overridable – the current dynamic-wind would be renamed to primitive-dynamic-wind, dynamic-wind would default to primitive-dynamic-wind but could be overriden (maybe with a parameter), and userspace scheduler libraries can override ‘dynamic-wind’ such that the ‘in-guard’ & ‘out-guard’ is _not_ run when 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-local variable with a similar API like parameters), it would use primitive-dynamic-wind, and if it needs a dynamic-wind for things like resource cleanup, it would use ‘dynamic-wind’.

While not quite integrated in Guile like this yet, for practical implementation see:
• https://github.com/wingo/fibers/commit/cc0e84cd56df3b07d378f710df39f8822317a2a2https://git.sr.ht/~old/guile-parallel/tree/master/item/parallel.scm#L29
• (what’s missing here, is a way to override Guile’s dynamic-wind in a transparent manner)

Best regards,
Maxime Devos


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

      reply	other threads:[~2024-12-16 12:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16  8:43 [PATCH v3] rdelim: Add new procedure `for-line-in-file` Adam Faiz
2024-12-16 11:27 ` Tomas Volf
2024-12-16 13:08   ` Nala Ginrut
2024-12-16 11:33 ` Ricardo Wurmus
2024-12-16 12:18   ` Maxime Devos [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241216131845.pQJl2D0051dDhme01QJlpW@laurent.telenet-ops.be \
    --to=maximedevos@telenet.be \
    --cc=adam.faiz@disroot.org \
    --cc=guile-devel@gnu.org \
    --cc=nalaginrut@gmail.com \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).