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.devel Subject: Re: Non-stack-copying call-with-current-continuation? Date: Sun, 04 Mar 2012 19:35:33 -0500 Message-ID: <87zkbvyje2.fsf@netris.org> References: <87ty27eus4.fsf@fencepost.gnu.org> <87mx7zesuw.fsf@fencepost.gnu.org> <87ipineqel.fsf@fencepost.gnu.org> <87eht9bmno.fsf@pobox.com> <87wr7060e6.fsf@fencepost.gnu.org> <87booca7er.fsf@pobox.com> <87sjho5uxb.fsf@fencepost.gnu.org> <874nu4yzkz.fsf@netris.org> <871up83qp2.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330907876 19141 80.91.229.3 (5 Mar 2012 00:37:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 5 Mar 2012 00:37:56 +0000 (UTC) Cc: guile-devel@gnu.org To: David Kastrup Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Mar 05 01:37:55 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 1S4Lw2-00073r-SG for guile-devel@m.gmane.org; Mon, 05 Mar 2012 01:37:54 +0100 Original-Received: from localhost ([::1]:60615 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4Lw2-0002EL-9N for guile-devel@m.gmane.org; Sun, 04 Mar 2012 19:37:54 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:35560) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4Lvy-0002EF-RV for guile-devel@gnu.org; Sun, 04 Mar 2012 19:37:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S4Lvw-0003S8-PH for guile-devel@gnu.org; Sun, 04 Mar 2012 19:37:50 -0500 Original-Received: from world.peace.net ([96.39.62.75]:45821) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S4Lvw-0003Qe-L6; Sun, 04 Mar 2012 19:37:48 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1S4Lvd-0006gY-C2; Sun, 04 Mar 2012 19:37:29 -0500 In-Reply-To: <871up83qp2.fsf@fencepost.gnu.org> (David Kastrup's message of "Mon, 05 Mar 2012 00:13:29 +0100") 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: 96.39.62.75 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:14006 Archived-At: David Kastrup writes: > Mark H Weaver writes: > >> David Kastrup writes: >> >>> The symbol name is not garbage collected. That is the difference >>> between gensym and make-symbol. >> >> Integers are plentiful and cheap. > > We are not talking about an integer generated statically here. We are > talking about integers getting burned through every time a control > structure is being used. Not at compilation time, but at runtime. And > with today's computers, executing a loop often enough that the integers > don't fit into a single Scheme cell anymore and stop being cheap is not > really an extraordinary event. Indeed, this is a good point, and another reason why we need the efficient gensym hack. >> Also, in Guile 2, prompt tags need not be symbols. Anything that can >> be compared with 'eq?' will work. > > I suppose there is no compelling technical reason why this could not be > made to also work with catch/throw, right? Being able to use something > like (list #f) instead of gensym would seriously reduce the cost, both > felt as well as actual. Indeed, I see no reason why catch/throw shouldn't accept non-symbol tags. Looking through the code of Guile 1.8, I see nothing that depends upon the tag being a symbol. Unfortunately, catch/throw have long been documented as requiring a symbol, and raise an error if given a non-symbol, at least as far back as Guile 1.4. However, catch/throw _will_ accept uninterned symbols created with 'make-symbol'. Here's a faster implementation of call/ec that uses (list 'call/ec) to create prompt tags on Guile 2, and (make-symbol "call/ec") on earlier versions of Guile: (cond-expand (guile-2 (define (call-with-escape-continuation proc) (let ((tag (list 'call/ec))) (call-with-prompt tag (lambda () (proc (lambda xs (abort-to-prompt tag xs)))) (lambda (k xs) (apply values xs)))))) (guile (define (call-with-escape-continuation proc) (let ((key (make-symbol "call/ec"))) (catch key (lambda () (proc (lambda xs (throw key xs)))) (lambda (key xs) (apply values xs))))))) (define call/ec call-with-escape-continuation) Regards, Mark