From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Wolfgang J Moeller Newsgroups: gmane.lisp.guile.bugs Subject: Re: shift and reset in ice-9 control Date: Sat, 2 Apr 2011 16:40:12 +0200 (CEST) Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Trace: dough.gmane.org 1301755281 31761 80.91.229.12 (2 Apr 2011 14:41:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 2 Apr 2011 14:41:21 +0000 (UTC) Cc: bug-guile@gnu.org To: Andy Wingo Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Apr 02 16:41:10 2011 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q620k-0004R8-2C for guile-bugs@m.gmane.org; Sat, 02 Apr 2011 16:41:10 +0200 Original-Received: from localhost ([127.0.0.1]:43692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q620j-0007Fu-2T for guile-bugs@m.gmane.org; Sat, 02 Apr 2011 10:41:09 -0400 Original-Received: from [140.186.70.92] (port=38467 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q620P-00076u-1j for bug-guile@gnu.org; Sat, 02 Apr 2011 10:40:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q620N-0008E5-85 for bug-guile@gnu.org; Sat, 02 Apr 2011 10:40:48 -0400 Original-Received: from mailer.gwdg.de ([134.76.10.26]:58380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q620M-0008Cp-Vf for bug-guile@gnu.org; Sat, 02 Apr 2011 10:40:47 -0400 Original-Received: from gwdw03.gwdg.de ([134.76.5.10]) by mailer.gwdg.de with esmtps (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1Q6204-0007WK-Sw; Sat, 02 Apr 2011 16:40:29 +0200 In-Reply-To: X-Virus-Scanned: (clean) by exiscan+sophie X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 134.76.10.26 X-BeenThere: bug-guile@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:5413 Archived-At: On Wed, 30 Mar 2011, Andy Wingo wrote: > On Mon 21 Mar 2011 02:31, Wolfgang J Moeller writes: >[...] > > However, I don't like it anymore, since I seem to have learned > > that this "direct implementation" doesn't at all play well > > with the use of call/cc within the s, while the call/cc-based > > implementations of shift/reset appear to do so. > > > > I've yet to find out why the latter work "better", and if there's > > a remedy possible using something like with-continuation-barrier ... > > Can you give some examples? In Guile things should work fine, AIUI. > > In the future (i.e., 2.2), I would like to change continuations to > capture just the Scheme stack, and optionally delimit their extent to a > prompt. I recommend Flatt et al's ICFP 2007 paper for a discussion. Interesting, but only in order to re-inspect "my" DYNAMIC-WIND, whose interactions with CALL-WITH-PROMPT and ABORT-TO-PROMPT I've not even tested yet. No, I'm not concerned with the implementation of the primitives, but with an attempt of mine to express a co-routine linkage using reset/shift (would you know of an example in the literature?). A stripped-down example goes like this: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (f1 ret) (let ((c #f)) (do ((n 0 (+ n 1))) ((> n 2) #f) (display n) ; at start of new line (case n ((0) (ret n)) ((1) (ret (call/cc (lambda (k) (set! c k) -1)))) (else (c n)))))) ;; (let ((dc #f) (saymax 5)) ;; (define (return-saving-dc v) (shift d (begin (set! dc d) v))) ;; (define (say . vs) (set! saymax (- saymax 1)) (if (negative? saymax) (error "saymax < 0")) (for-each display vs) (newline)) ;; (say "#0: " (reset (f1 return-saving-dc))) ;; (say "#1: " (dc "ignored.1")) (say "#2: " (dc "ignored.2")) (say "#3: " (dc "ignored.3")) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Think of (f1) as a sort-of co-routine and of (return-saving-dc) as my best attempt to save co-routine state using reset/shift only. Using the "direct" implementaion of reset/shift (mine seems to agree with Flatt et.al.), it goes into a loop since (dc "ignored.2") makes (f1) restore the full continuation that makes (dc "ignored.1") return one more time - "dc" isn't so "delimited" after all. Remarkably, the example works out differently (no loop) with either call/cc-based implementation of reset/shift that I know of (one using a "meta-continuation", the other a continuation stack) - as I understand it, this comes from the delimited continuations always returning via another full continuation that was captured at invocation time. Maybe it's a "discovery" that the different implementations of reset/shift do have observably different outcomes ... And because I had first played with call/cc-based reset/shift, I had the impression that it's indeed possible to do co-routine linkage using these primitives w/o requiring call/cc. Then there came GUILE V2 and made me try out the "direct" way, plus I (incidentally) had call/cc (only for _local_ transfer of control, just like in the example) in one of my co-routines ... that's why I (at the moment) dislike the "direct" implementation. I haven't yet found a place where adding (with-continuation barrier) [as in GUILE V2.0.0, at least] could help me; next thing was to think hard about the potential of (dynamic-wind). === Some confusing observations about a "borderline" case (evaluation of (define) determines "definition"-property of the next statement) at GUILE V2's toplevel: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (begin (define dummy1 (eval ;; '(defmacro macro-case clauses (let lp ((cs clauses)) (if (null? cs) '(define dummy2 #f) (if (or (and (symbol? (caar cs)) (eq? (caar cs) 'else)) (eval (caar cs) (interaction-environment))) (cons 'begin (cdar cs)) (lp (cdr cs)))))) ;; (interaction-environment))) ) ;; (macro-case (#f (define something #t))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (That's just the traditional _structure_ of my prelude, intended to have nothing but definitions at the toplevel). Depending upon what I do with this snippet (auto-compile, load vs. include), it sometimes gets accepted by GUILE V2.0.0: auto,include auto,load noauto,include noauto,load --------------------------------------------------------------------------- @toplevel Error Error Error OK surroundes by BEGIN Error Error Error Error EVAL-WHEN OK OK OK Error To add to the weirdness, removing the (supposedly redundant) BEGIN around (DEFINE dummy1) reverses most of the outcomes ... Not a serious problem - just confusing! === Best regards, Wolfgang J. Moeller, Tel. +49 551 47361, wjmheenes.com 37085 Goettingen, Germany | Disclaimer: No claim intended! http://www.wjmoeller.de/ -+-------- http://www.heenes.com/