From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: =?UTF-8?B?VsOtdG9yIERlIEFyYcO6am8=?= Newsgroups: gmane.lisp.guile.user Subject: Re: dynamic-wind Date: Sun, 9 Jul 2017 11:09:25 -0300 Message-ID: <59623915.6070104@sapo.pt> References: <20170709135921.0f4890ad@bother.homenet> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Trace: blaine.gmane.org 1499609406 29070 195.159.176.226 (9 Jul 2017 14:10:06 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 9 Jul 2017 14:10:06 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.8.0 To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jul 09 16:10:01 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dUCuL-00074A-3U for guile-user@m.gmane.org; Sun, 09 Jul 2017 16:09:57 +0200 Original-Received: from localhost ([::1]:36319 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUCuQ-0008Nx-Ez for guile-user@m.gmane.org; Sun, 09 Jul 2017 10:10:02 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33925) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dUCu3-0008Ng-5c for guile-user@gnu.org; Sun, 09 Jul 2017 10:09:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dUCtz-00015v-Vq for guile-user@gnu.org; Sun, 09 Jul 2017 10:09:39 -0400 Original-Received: from relay5.ptmail.sapo.pt ([212.55.154.25]:46761 helo=sapo.pt) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dUCtz-00014h-KB for guile-user@gnu.org; Sun, 09 Jul 2017 10:09:35 -0400 Original-Received: (qmail 12550 invoked from network); 9 Jul 2017 14:09:31 -0000 Original-Received: (qmail 16891 invoked from network); 9 Jul 2017 14:09:30 -0000 Original-Received: from unknown (HELO [192.168.0.19]) (vbuaraujo@sapo.pt@[201.21.60.109]) (envelope-sender ) by ptmail-mta-auth01 (qmail-ptmail-1.0.0) with ESMTPSA for ; 9 Jul 2017 14:09:30 -0000 X-PTMail-RemoteIP: 201.21.60.109 X-PTMail-AllowedSender-Action: X-PTMail-Service: default In-Reply-To: <20170709135921.0f4890ad@bother.homenet> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 212.55.154.25 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:13911 Archived-At: On 09/07/2017 09:59, Chris Vine wrote: > On Sun, 09 Jul 2017 00:34:13 +0300 > Marko Rauhamaa 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/