* Unwind-protect
@ 2024-10-28 10:00 Tommi Höynälänmaa
2024-10-28 10:29 ` Unwind-protect tomas
0 siblings, 1 reply; 7+ messages in thread
From: Tommi Höynälänmaa @ 2024-10-28 10:00 UTC (permalink / raw)
To: guile-user
Does Guile have unwind-protect? If not, how could it be implemented?
--
Kotisivu / Homepage: http://www.iki.fi/tohoyn/
Sähköposti / E-Mail: tommi.hoynalanmaa@iki.fi
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unwind-protect
2024-10-28 10:00 Unwind-protect Tommi Höynälänmaa
@ 2024-10-28 10:29 ` tomas
0 siblings, 0 replies; 7+ messages in thread
From: tomas @ 2024-10-28 10:29 UTC (permalink / raw)
To: Tommi Höynälänmaa; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
On Mon, Oct 28, 2024 at 12:00:54PM +0200, Tommi Höynälänmaa wrote:
> Does Guile have unwind-protect? If not, how could it be implemented?
I think you are looking for dynamic-wind: this one covers the fact
that in Scheme, you can not only leave a dynamic context through
the side door -- you can enter it, too,
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unwind-protect
@ 2024-10-28 14:55 Tommi Höynälänmaa
2024-10-28 16:57 ` Unwind-protect tomas
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tommi Höynälänmaa @ 2024-10-28 14:55 UTC (permalink / raw)
To: tomas; +Cc: guile-user
Unwind-protect and dynamic-wind are not the same thing. See
http://www.nhplace.com/kent/PFAQ/unwind-protect-vs-continuations-original.html
- Tommi
--
Kotisivu / Homepage: http://www.iki.fi/tohoyn/
Sähköposti / E-Mail: tommi.hoynalanmaa@iki.fi
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unwind-protect
2024-10-28 14:55 Unwind-protect Tommi Höynälänmaa
@ 2024-10-28 16:57 ` tomas
2024-10-28 17:20 ` Unwind-protect Maxime Devos via General Guile related discussions
2024-10-28 17:34 ` Unwind-protect Maxime Devos via General Guile related discussions
2 siblings, 0 replies; 7+ messages in thread
From: tomas @ 2024-10-28 16:57 UTC (permalink / raw)
To: Tommi Höynälänmaa; +Cc: guile-user
[-- Attachment #1: Type: text/plain, Size: 549 bytes --]
On Mon, Oct 28, 2024 at 04:55:01PM +0200, Tommi Höynälänmaa wrote:
> Unwind-protect and dynamic-wind are not the same thing. See
>
> http://www.nhplace.com/kent/PFAQ/unwind-protect-vs-continuations-original.html
I know (thanks for the interesting link, anyway :)
BTW: doesn't Guile favour delimited continuations these days?
How would things change in view of that?
Of course, if you're building a generic Scheme library, you'll
have to cope with the fact that full continuations are part of
the language spec.
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Unwind-protect
2024-10-28 14:55 Unwind-protect Tommi Höynälänmaa
2024-10-28 16:57 ` Unwind-protect tomas
@ 2024-10-28 17:20 ` Maxime Devos via General Guile related discussions
2024-10-28 17:34 ` Unwind-protect Maxime Devos via General Guile related discussions
2 siblings, 0 replies; 7+ messages in thread
From: Maxime Devos via General Guile related discussions @ 2024-10-28 17:20 UTC (permalink / raw)
To: Tommi Höynälänmaa, tomas@tuxteam.de; +Cc: guile-user@gnu.org
>Unwind-protect and dynamic-wind are not the same thing. See
>http://www.nhplace.com/kent/PFAQ/unwind-protect-vs-continuations-original.html
>
> - Tommi
Err, that web page is simply incorrect on this matter, unless Lisp and Scheme are assigning different meanings to the same words. (If they do mean something different, you’ll need to tell what semantics you want the unwind-protect equivalent to have.)
Let’s look at the semantics of unwind-protect: https://lisp-docs.github.io/cl-language-reference/chap-5/f-d-dictionary/unwind-protect_special-operator:
>unwind-protect evaluates protected-form and guarantees that cleanup-forms are executed before unwind-protect exits, whether it terminates normally or is aborted by a control transfer of some kind.
>[…]
>unwind-protect protects against *all* attempts to exit from protected-form, including go, handler-case, ignore-errors, restart-case, return-from, throw, and with-simple-restart.
(emphasis added)
Now compare it to the web page:
>Sometimes when I cite this problem, people tell me that dynamic-wind is the solution. It is not. dynamic-wind exists to solve a completely different problem. The purpose of dynamic-wind is to taken action on *every* entry and every exit to a dynamic contour for effects that can be undone and redone. For example, dynamic-wind can be used to implement what Common Lisp calls special variables (i.e., "dynamic" variables).
These descriptions of dynamic-wind and unwind-protect describe the same sematics.
That said, the web page is correct that dynamic-wind often isn’t a proper solution. But likewise, neither would unwind-protect be a proper solution (in the presence of continuations).
Under the assumption that continuations are used as a form of userspace context-switching and that dynamic-wind is used for cleanup (and maybe acquisition if you want to) of resources (and this cleanup shouldn’t be caused by context switching), I do have a solution (LGPL3+, albeit perhaps with an argument for triviality):
https://github.com/wingo/fibers/blob/f92e5cb4f78e7e3d3537bfc9622bc59ea99fe9a7/fibers/scheduler.scm#L281
It’s a bit ad-hoc currently, but I imagine it would be possible to rename the currently-existing dynamic-wind to primitive-dynamic-wind and rename dynamic-wind
--
Kotisivu / Homepage: http://www.iki.fi/tohoyn/
Sähköposti / E-Mail: tommi.hoynalanmaa@iki.fi
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Unwind-protect
2024-10-28 14:55 Unwind-protect Tommi Höynälänmaa
2024-10-28 16:57 ` Unwind-protect tomas
2024-10-28 17:20 ` Unwind-protect Maxime Devos via General Guile related discussions
@ 2024-10-28 17:34 ` Maxime Devos via General Guile related discussions
2 siblings, 0 replies; 7+ messages in thread
From: Maxime Devos via General Guile related discussions @ 2024-10-28 17:34 UTC (permalink / raw)
To: Tommi Höynälänmaa, tomas@tuxteam.de; +Cc: guile-user@gnu.org
[I accidentally sent an incomplete version, here’s the rest]
Under the assumption that continuations are used as a form of userspace context-switching and that dynamic-wind is used for cleanup (and maybe acquisition if you want to) of resources (and this cleanup shouldn’t be caused by context switching), I do have a solution (LGPL3+, albeit perhaps with an argument for triviality):
https://github.com/wingo/fibers/blob/f92e5cb4f78e7e3d3537bfc9622bc59ea99fe9a7/fibers/scheduler.scm#L281
It’s a bit ad-hoc currently, but I imagine it would be possible to:
• rename the currently-existing dynamic-wind to primitive-dynamic-wind
• create a fluid (not parameter!) %dynamic-wind-stack
• define (dynamic-wind a b c) as ((fluid-ref* %dynamic-wind-stack 0) a b c 0)
• initial value for %dynamic-wind-stack is (lambda (a b c n) (primitive-dynamic-wind* a b c))
• replacements for dynamic-wind (implemented by userspace threading equivalents) can be added by a fluid binding, and typically all ‘dynamic-winders’ (except primitive-dynamic-wind) would be implemented by calling binding before it (positions indicated via ‘n’)
After some API abstraction to somehow hide the fluid and the argument ‘n’, this seems like a simple and composable replacement for dynamic-wind to me. (Some overhead involved, but it’s not like you would call dynamic-wind in a tight loop.)
Technically it’s technically against the RnRS rules, but IMO winding and continuation is a matter of perspective – I mean, a syscall is a kernel<->userspace abort-to-prompt, yet typically you don’t want dynamic-wind to consider those as non-local control flow.
Best regards,
Maxime Devos
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Unwind-protect
@ 2024-10-28 15:35 Tommi Höynälänmaa
0 siblings, 0 replies; 7+ messages in thread
From: Tommi Höynälänmaa @ 2024-10-28 15:35 UTC (permalink / raw)
To: tomas; +Cc: guile-user
Actually I found a simple solution for this problem.
- Tommi
--
Kotisivu / Homepage: http://www.iki.fi/tohoyn/
Sähköposti / E-Mail: tommi.hoynalanmaa@iki.fi
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-28 17:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-28 10:00 Unwind-protect Tommi Höynälänmaa
2024-10-28 10:29 ` Unwind-protect tomas
-- strict thread matches above, loose matches on Subject: below --
2024-10-28 14:55 Unwind-protect Tommi Höynälänmaa
2024-10-28 16:57 ` Unwind-protect tomas
2024-10-28 17:20 ` Unwind-protect Maxime Devos via General Guile related discussions
2024-10-28 17:34 ` Unwind-protect Maxime Devos via General Guile related discussions
2024-10-28 15:35 Unwind-protect Tommi Höynälänmaa
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).