From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.lisp.guile.devel Subject: Re: Non-stack-copying call-with-current-continuation? Date: Fri, 02 Mar 2012 09:36:50 +0100 Organization: Organization?!? Message-ID: <87ehtbe6vx.fsf@fencepost.gnu.org> References: <87ty27eus4.fsf@fencepost.gnu.org> <87mx7zesuw.fsf@fencepost.gnu.org> <87ipineqel.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1330677437 9655 80.91.229.3 (2 Mar 2012 08:37:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 2 Mar 2012 08:37:17 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 02 09:37:17 2012 Return-path: Envelope-to: guile-devel@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 1S3NzD-0007EP-JI for guile-devel@m.gmane.org; Fri, 02 Mar 2012 09:37:11 +0100 Original-Received: from localhost ([::1]:44406 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3NzC-0000f9-8t for guile-devel@m.gmane.org; Fri, 02 Mar 2012 03:37:10 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:45091) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3Nz9-0000f3-Aa for guile-devel@gnu.org; Fri, 02 Mar 2012 03:37:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3Nz7-0001VO-Gl for guile-devel@gnu.org; Fri, 02 Mar 2012 03:37:06 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:44011) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3Nz7-0001VC-6R for guile-devel@gnu.org; Fri, 02 Mar 2012 03:37:05 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1S3Nz3-00079m-L6 for guile-devel@gnu.org; Fri, 02 Mar 2012 09:37:01 +0100 Original-Received: from p57b9ea27.dip.t-dialin.net ([87.185.234.39]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 Mar 2012 09:37:01 +0100 Original-Received: from dak by p57b9ea27.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 02 Mar 2012 09:37:01 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 72 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: p57b9ea27.dip.t-dialin.net X-Face: 2FEFf>]>q>2iw=B6, xrUubRI>pR&Ml9=ao@P@i)L:\urd*t9M~y1^:+Y]'C0~{mAl`oQuAl \!3KEIp?*w`|bL5qr,H)LFO6Q=qx~iH4DN; i"; /yuIsqbLLCh/!U#X[S~(5eZ41to5f%E@'ELIi$t^ Vc\LWP@J5p^rst0+('>Er0=^1{]M9!p?&:\z]|;&=NP3AhB!B_bi^]Pfkw User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:wv3/kj07iVKuRKwJSNoQJDV1lXg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13981 Archived-At: Noah Lavine writes: > Hello, > >> Sure, but things like gensym and make-prompt-tag (and (list '()) for >> creating an eq?-unique object) are artificial hygiene coming at a cost >> in symbol table and symbol generation time rather than "lexical" >> hygiene.  They need _extra_ work, whereas the >> call-with-current-continuation approach needed _less_ work.  Basically I >> want something like call-with-single-continuation that will only allow >> one return (and any dynwind out counts and should work if it is the >> first, so it is not exactly equivalent to using >> with-continuation-barrier) and come without the stack-copying cost of >> call-with-current-continuation. > > I agree that it's not pretty. We have hygienic macros so we don't have > to use gensym, after all. But I don't know of a better way. Well, to wrap this up: the manual (not current) states It is traditional in Scheme to implement exception systems using `call-with-current-continuation'. Continuations (*note Continuations::) are such a powerful concept that any other control mechanism -- including `catch' and `throw' -- can be implemented in terms of them. [...] The more targeted mechanism provided by `catch' and `throw' does not need to save and restore the C stack because the `throw' always jumps to a location higher up the stack of the code that executes the `throw'. Therefore Guile implements the `catch' and `throw' primitives independently of `call-with-current-continuation', in a way that takes advantage of this _upwards only_ nature of exceptions. I think that using something like "call-with-single-continuation" as the underlying primitive would make Guile quite more similar to "traditional" systems in the code base. It would also provide a minimally-invasive tool for tuning existing code based on call-with-current-continuation in case that the stack copying semantics are _not_ required. Definitely more Schemeish than stuff like, uh, prompts? > Well, I can't fix all of that, but you could at least make it fail > better like this: > > (define (call-with-single-continuation proc) > (let ((tag (gensym)) > (thrown #f)) > (catch tag > (proc (lambda x (if thrown (error "Single continuation called > twice") (throw tag x))) > (lambda (tag . x) (apply values x))))) > > I think that will do what you want. It would help to actually set "thrown" somewhere (which is sort of tricky considering that you need to set it also on regular return). You wrap x into a list once too often (first with lambda x, then with lambda (tag . x)). But I get the drift. > It doesn't look too bad to me, although I agree with your point in > general - using symbols to denote names, like prompts, undoes the > hygiene that Scheme is supposed to have. But the only solution I can > think of is pretty messy. Yup. call-with-single-continuation would make best sense as a primitive for building other stuff, not the other way round. -- David Kastrup