From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Matt Hellige Newsgroups: gmane.lisp.guile.user Subject: Continuations: possible newbie question Date: Tue, 17 Dec 2002 18:14:25 -0600 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <20021217181424.A22845@metro.immute.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1040171459 9378 80.91.224.249 (18 Dec 2002 00:30:59 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 18 Dec 2002 00:30:59 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18OS6z-0002R7-00 for ; Wed, 18 Dec 2002 01:30:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18OS5Z-00025w-03 for guile-user@m.gmane.org; Tue, 17 Dec 2002 19:29:29 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18OS5E-00024T-00 for guile-user@gnu.org; Tue, 17 Dec 2002 19:29:08 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18OS5B-00022S-00 for guile-user@gnu.org; Tue, 17 Dec 2002 19:29:07 -0500 Original-Received: from immute.net ([65.164.210.194]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18OS5B-00020w-00 for guile-user@gnu.org; Tue, 17 Dec 2002 19:29:05 -0500 Original-Received: (from matt@localhost) by immute.net (8.9.3/8.9.3) id SAA22913 for guile-user@gnu.org; Tue, 17 Dec 2002 18:14:25 -0600 Original-To: guile-user@gnu.org Mail-Followup-To: guile-user@gnu.org Content-Disposition: inline User-Agent: Mutt/1.2.5i X-Mailer-Holy-War: Get Mutt, it bites! X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1454 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1454 I'm trying to use guile in a software project, and have encountered a snag. It may be my imperfect understanding of continuations, but it seems weird. First a little background... I'm trying to use guile to implement key bindings, planning to bind key-strokes to thunks. I'd like to be able to write a key binding like: (define (mythunk) (goto-item (get-string))) (bind-key "g" mythunk) where goto-item and get-string are primitives. Now, the issue is that get-string needs to do some interaction with the user, so i'd like to be able to return to the main application loop to do the interaction, then cause get-string to return the result. To do this, I figured I could use a combination of exceptions and call/cc. But I can't seem to get it to work. I have a simple test case set up that demonstrates the problem. Given the following definitions: (define call/cc call-with-current-continuation) (define cont #f) (define (get-string) (let ((result (call/cc (lambda (c) (set! cont c) #f)))) (if result result (throw 'interact)))) (define (done-reading result) (if cont (let ((tmp cont)) (set! cont #f) (tmp result)))) (define (bind) (display (get-string))(newline)) (define (exec-binding thunk) (catch 'interact thunk (lambda (key) "escaped"))) Here's what I'd expect: guile> (exec-binding bind) "escaped" guile> (done-reading "hi") hi guile> But here's what I get: guile> (exec-binding bind) "escaped" guile> (done-reading "hi") (((()) #)) guile> guile> guile> (exec-binding bind) "escaped" guile> (done-reading "hi") (# # . #i(Segmentation fault Notice that it changes between the first and second tries, and also please notice the seg fault... This definitely doesn't seem quite right! It also behaves similarly if I try (exec-binding get-string), although it doesn't always crash. On the other hand, the following seems to work correctly: guile> (get-string) : In procedure gsubr-apply in expression (throw (quote interact)): : unhandled-exception: interact ABORT: (misc-error) Type "(backtrace)" to get more information or "(debug)" to enter the debugger. guile> (done-reading "hi") "hi" guile> The error, of course, is due to the fact that we're no longer in exec-binding when the exception is thrown. So, my question basically is: is this due to a bug in guile, or to my abuse of continuations? Either way, can anyone suggest another way to do what I'm trying to do? I'm rather new to this, so my solution may be too convoluted to begin with. If no one here can suggest anything, is there a more general scheme forum that I could try? This is all using guile-1.6.0. Thanks very much! Matt -- Matt Hellige matt@immute.net http://matt.immute.net _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user