From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Noah Lavine Newsgroups: gmane.lisp.guile.devel Subject: Re: Non-stack-copying call-with-current-continuation? Date: Thu, 1 Mar 2012 19:20:01 -0500 Message-ID: References: <87ty27eus4.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: quoted-printable X-Trace: dough.gmane.org 1330647615 24030 80.91.229.3 (2 Mar 2012 00:20:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 2 Mar 2012 00:20:15 +0000 (UTC) Cc: guile-devel@gnu.org To: David Kastrup Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Mar 02 01:20:14 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 1S3GEH-0005t0-WF for guile-devel@m.gmane.org; Fri, 02 Mar 2012 01:20:14 +0100 Original-Received: from localhost ([::1]:35094 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3GEH-0003t8-By for guile-devel@m.gmane.org; Thu, 01 Mar 2012 19:20:13 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:42118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3GEE-0003sk-82 for guile-devel@gnu.org; Thu, 01 Mar 2012 19:20:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S3GEC-0007DZ-Ew for guile-devel@gnu.org; Thu, 01 Mar 2012 19:20:09 -0500 Original-Received: from mail-iy0-f169.google.com ([209.85.210.169]:36250) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S3GE9-00079M-1q; Thu, 01 Mar 2012 19:20:05 -0500 Original-Received: by iajr24 with SMTP id r24so1864931iaj.0 for ; Thu, 01 Mar 2012 16:20:01 -0800 (PST) Received-SPF: pass (google.com: domain of noah549@gmail.com designates 10.50.173.3 as permitted sender) client-ip=10.50.173.3; Authentication-Results: mr.google.com; spf=pass (google.com: domain of noah549@gmail.com designates 10.50.173.3 as permitted sender) smtp.mail=noah549@gmail.com; dkim=pass header.i=noah549@gmail.com Original-Received: from mr.google.com ([10.50.173.3]) by 10.50.173.3 with SMTP id bg3mr48243igc.12.1330647601871 (num_hops = 1); Thu, 01 Mar 2012 16:20:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=cKW21FXp9z0fa1j9MsqjnXGVURcgNJtm0rcerx78QJM=; b=hatG0ya94UWKqh3OmbabSdGdn6c9XehGcus64ZIuzf27zV4cVG1lcIJd6qXis2PJ6I jvAELC3/uUXbnPucLopDWPKXsVFwt5F5UQfSTQ1LUUYGU9dZzYvzuqgDEbHexsPG53B5 V2DcLT4UdHpCpwLlxEcFqyvBlpPzQ0jvqLySiIoyY8ehuCLwCN/7gulqeXw8xN6GzvPg ezVSZjTEnoacdEDuEHxdWNAzlYPG44wHTIjwncuwBPljHuGBdaMHK1cLbe/n+UXe8CL6 wt7C51/Wx5QOLaP4lsJPeQbciJLG+mCA589H2eyykPD03EbJrTQ6bqr7Bl6fNG13PPZo 5S9g== Original-Received: by 10.50.173.3 with SMTP id bg3mr40230igc.12.1330647601821; Thu, 01 Mar 2012 16:20:01 -0800 (PST) Original-Received: by 10.231.16.199 with HTTP; Thu, 1 Mar 2012 16:20:01 -0800 (PST) In-Reply-To: <87ty27eus4.fsf@fencepost.gnu.org> X-Google-Sender-Auth: wlZwkighnS57rYAslHCWra-YcYU X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.169 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:13973 Archived-At: If I understand correctly, you only need to call the continuation once. Is that right? In that case, I think you could use either catch and throw or prompts. (And catch and throw are implemented with prompts, so really, you can just choose how you want to use prompts.) Noah On Thu, Mar 1, 2012 at 7:00 PM, David Kastrup wrote: > > Hi, > > I am just meddling around with coding and have come up with the > following: > > (define-public (find-child music predicate) > =A0"Find the first node in @var{music} that satisfies @var{predicate}." > =A0(catch 'music-found > =A0 =A0 =A0 =A0 (lambda () > =A0 =A0 =A0 =A0 =A0 (fold-some-music predicate > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda (music . _= ) (throw 'music-found music)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#f music)) > =A0 =A0 =A0 =A0 (lambda (key music) music))) > > Now the problem with that is that it is unhygienic. =A0If fold-some-music > were to use music-found signals, or if the predicate did, things would > be awkward. =A0One would need to work with a uniquely generated symbol. > It turns out that the above can be expressed much clearer and cleaner as > > (define-public (find-child music predicate) > =A0"Find the first node in @var{music} that satisfies @var{predicate}." > =A0(call-with-current-continuation > =A0 (lambda (music-found) > =A0 =A0 (fold-some-music predicate > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(lambda (music . _) (music-fou= nd music)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0#f music)))) > > at least if I did not make some thinko here. =A0It is basically the same > code and stack-upwards-only, but hygienic. =A0Nothing can call the > continuation but what is inside. =A0Well, of course fold-some-music could > save the closure calling music-found for later. =A0But it doesn't. > > Is there a way to get a call-with-current-continuation that does not > create a stack copy? =A0It is fine if it fails with an exception if one > still tries calling the continuation after it has already returned. > > -- > David Kastrup > >