From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#18356: Should partial continuations capture the dynamic environment? Date: Wed, 15 Oct 2014 12:37:28 -0400 Message-ID: <87bnpd70hj.fsf@yeeloong.lan> References: <87lhq7go7a.fsf@taylan.uni.cx> <87iojmlodk.fsf@taylan.uni.cx> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1413391176 32702 80.91.229.3 (15 Oct 2014 16:39:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Oct 2014 16:39:36 +0000 (UTC) Cc: 18356@debbugs.gnu.org, request@debbugs.gnu.org To: Taylan Ulrich Bayirli/Kammer Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Wed Oct 15 18:39:29 2014 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XeRbg-0004uc-Kb for guile-bugs@m.gmane.org; Wed, 15 Oct 2014 18:39:24 +0200 Original-Received: from localhost ([::1]:45754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeRbg-0006pJ-9b for guile-bugs@m.gmane.org; Wed, 15 Oct 2014 12:39:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38821) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeRbV-0006p1-VB for bug-guile@gnu.org; Wed, 15 Oct 2014 12:39:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeRbM-0001yZ-R9 for bug-guile@gnu.org; Wed, 15 Oct 2014 12:39:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53109) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeRbM-0001yV-N8 for bug-guile@gnu.org; Wed, 15 Oct 2014 12:39:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1XeRbM-0001Oc-8r for bug-guile@gnu.org; Wed, 15 Oct 2014 12:39:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Wed, 15 Oct 2014 16:39:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18356 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 18356-submit@debbugs.gnu.org id=B18356.14133910945306 (code B ref 18356); Wed, 15 Oct 2014 16:39:03 +0000 Original-Received: (at 18356) by debbugs.gnu.org; 15 Oct 2014 16:38:14 +0000 Original-Received: from localhost ([127.0.0.1]:44673 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XeRaX-0001NQ-Lv for submit@debbugs.gnu.org; Wed, 15 Oct 2014 12:38:14 -0400 Original-Received: from world.peace.net ([96.39.62.75]:40374) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XeRaU-0001N7-Ig; Wed, 15 Oct 2014 12:38:11 -0400 Original-Received: from c-24-62-95-23.hsd1.ma.comcast.net ([24.62.95.23] helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1XeRaM-0005Hk-Lb; Wed, 15 Oct 2014 12:38:02 -0400 In-Reply-To: <87iojmlodk.fsf@taylan.uni.cx> (Taylan Ulrich Bayirli's message of "Tue, 14 Oct 2014 16:25:27 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.94 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7616 Archived-At: tags 18356 + notabug close 18356 thanks Taylan Ulrich Bayirli/Kammer writes: > In short, no: partial continuations in Guile should not (and do not) > capture their dynamic environment. I think this requires further explanation, because the above statement is not quite correct. Partial continuations do not capture the _entire_ dynamic environment, but they *do* capture (and later restore) the _part_ of the dynamic environment that was established between the prompt and abort. Thinking in terms of 'dynamic-wind', 'abort-to-prompt' unwinds from the abort to the prompt, and when the partial continuation is later invoked, it will rewind from the prompt back to the abort before resuming the computation. Thinking in terms of dynamic environments, 'abort-to-prompt' captures the dynamic bindings that were established between the prompt and abort, and these captured bindings are composed on top of the dynamic environment of the call site when the partial continuation is later invoked. So, for example: --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (call-with-prompt 'foo (lambda () (dynamic-wind (lambda () (display "entering\n")) (lambda () (abort-to-prompt 'foo)) (lambda () (display "leaving\n")))) (lambda (k) k)) entering leaving $1 = # scheme@(guile-user)> ($1 'hello) entering leaving $2 = hello --8<---------------cut here---------------end--------------->8--- Above, the 'dynamic-wind' between the prompt and abort is rewound when invoking the partial continuation. --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (dynamic-wind (lambda () (display "entering\n")) (lambda () (call-with-prompt 'foo (lambda () (abort-to-prompt 'foo)) (lambda (k) k))) (lambda () (display "leaving\n"))) entering leaving $3 = # scheme@(guile-user)> ($3 'hello) $4 = hello --8<---------------cut here---------------end--------------->8--- Above, the 'dynamic-wind' outside of the prompt is _not_ rewound when invoking the partial continuation. --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (define my-param (make-parameter #f)) scheme@(guile-user)> (call-with-prompt 'foo (lambda () (parameterize ((my-param 5)) ((abort-to-prompt 'foo)))) (lambda (k) k)) $5 = # scheme@(guile-user)> ($5 my-param) $6 = 5 --8<---------------cut here---------------end--------------->8--- Above, the dynamic binding of 'my-param' to 5 is restored when invoking the partial continuation, because it was established between the prompt and abort. --8<---------------cut here---------------start------------->8--- scheme@(guile-user)> (parameterize ((my-param 5)) (call-with-prompt 'foo (lambda () ((abort-to-prompt 'foo))) (lambda (k) k))) $7 = # scheme@(guile-user)> ($7 my-param) $8 = #f --8<---------------cut here---------------end--------------->8--- Above, the dynamic-binding of 'my-param' to 5 is _not_ restored, because it was established outside of the prompt. Mark