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 02:35:14 +0100 Message-ID: <87ipineqel.fsf@fencepost.gnu.org> References: <87ty27eus4.fsf@fencepost.gnu.org> <87mx7zesuw.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330652395 21473 80.91.229.3 (2 Mar 2012 01:39:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 2 Mar 2012 01:39:55 +0000 (UTC) Cc: guile-devel@gnu.org To: Noah Lavine Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 02 02:39:54 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 1S3HTK-00022m-8g for guile-devel@m.gmane.org; Fri, 02 Mar 2012 02:39:50 +0100 Original-Received: from localhost ([::1]:60149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3HTJ-0000Um-Gi for guile-devel@m.gmane.org; Thu, 01 Mar 2012 20:39:49 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:33827) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3HTG-0000Uh-5d for guile-devel@gnu.org; Thu, 01 Mar 2012 20:39:47 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3HTE-00082N-Gf for guile-devel@gnu.org; Thu, 01 Mar 2012 20:39:45 -0500 Original-Received: from fencepost.gnu.org ([208.118.235.10]:56754) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3HTE-00082J-D2 for guile-devel@gnu.org; Thu, 01 Mar 2012 20:39:44 -0500 Original-Received: from localhost ([127.0.0.1]:52238 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3HTC-0005BN-Gw; Thu, 01 Mar 2012 20:39:42 -0500 Original-Received: by lola (Postfix, from userid 1000) id 1467F2024DF; Fri, 2 Mar 2012 02:35:14 +0100 (CET) In-Reply-To: (Noah Lavine's message of "Thu, 1 Mar 2012 20:01:30 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.118.235.10 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:13978 Archived-At: Noah Lavine writes: > Oh yes, you're right. I'm sorry I missed it. > > I believe you can do it hygienically though. With prompts, you can use > (make-prompt-tag) to generate a new, unique tag. With catch and throw, > you could use (gensym) to do the same thing. You first example would > become something like > > (define-public (find-child music predicate) > "Find the first node in @var{music} that satisfies @var{predicate}." > (let ((music-found-tag (gensym))) > (catch music-found-tag > (lambda () > (fold-some-music predicate > (lambda (music . _) (throw music-found-tag music)) > #f music)) > (lambda (key music) music))) > > Does that work? 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. Sure, you can do (define (call-with-single-continuation proc) (let ((tag (gensym))) (catch tag (proc (lambda x (throw tag x))) (lambda (tag x) (apply values x))))) Oops. (apply values ...)? Does this even work? Anyway, you get the drift. But it is not pretty and it is not primitive. And its failure mode when you disobey the "single" contract is an uncaught exception with a weird symbol. -- David Kastrup