On 09/07/2017 09:59, Chris Vine wrote: > On Sun, 09 Jul 2017 00:34:13 +0300 > Marko Rauhamaa <ma...@pacujo.net> writes: >> Hm. Python's try/finally has several uses in virtually every >> program. >> >> Trouble is, Scheme's continuations make it impossible to know when >> something is really final. >> >> In fact, implementing coroutines and cooperative multitasking using >> continuations almost guarantee a repeated back-and-forth through >> dynamic-wind. >> >> I strongly suspect Scheme's continuations are more trouble than they >> are worth. > > I disagree with that. On the first point, you know that a > dynamic-wind block can no longer be re-entered (if that is what you mean > by "really final") when the continuation object concerned is no longer > accessible. At that point it, and all references to other objects > encapsulated by the continuation, will be released in the ordinary > way. You also know the same when your continuation is only an escape > continuation.
That helps the implementation know if a continuation will not be entered again, but it does not help when you want to do the kinds of things you do with unwind-protect or try/finally in other languages. For example, with unwind-protect, you can open a port or another resource and ensure it will be closed if control escapes the unwind-protect form. You can do that with dynamic-wind, but it is less meaningful to do so because control can be re-entered again. There is no language construct (as far as I know – maybe there is in Guile) that can detect that flow has exited the form and *will never enter it again*. So the presence of continuations make operations like unwind-protect less meaningful. I don't know what is the Scheme way to address these situations. > Secondly, this is something of an irrelevance. I have found it very > rare that one would want to use dynamic-wind when implementing > co-operative multi-tasking with coroutines (at any rate, > https://github.com/ChrisVine/guile-a-sync only does so for thread pool > thread counts, and that is to cater for exceptions in local code rather > than for jumps via continuation objects). Jumping out of a > dynamic-wind block using a coroutine is generally inimical to the kind > of asynchronous programming that coroutines are used for: you generally > don't want to unset the state of the continuation, and then set it up > again when you re-enter. You normally want to leave it just as it was > at the time you yielded. > > I may be mistaking you for another poster, but I think you have > previously said that you prefer the inversion of control ("callback > hell") style of asynchronous programming to using coroutines. You > would not usually think of using dynamic-wind there either, I hope. > > Scheme's continuations are very useful. Guile's delimited > continuations are even more so. Dynamic-wind not so much, because it > is a very blunt instrument. > > Chris > -- Vítor De Araújo https://elmord.org/