unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Re: Continuations: possible newbie question
@ 2002-12-18 18:42 Thien-Thi Nguyen
  2002-12-26 21:30 ` Found a bug in guile 1.6.0 Roland Orre
  0 siblings, 1 reply; 10+ messages in thread
From: Thien-Thi Nguyen @ 2002-12-18 18:42 UTC (permalink / raw
  Cc: guile-user

   From: Matt Hellige <matt@immute.net>
   Date: Wed, 18 Dec 2002 12:14:10 -0600

   what I should do to
   submit a bug report

it's probably sufficient to send a message to bug-guile saying "see
thread ``Continuations: ...'' in guile-user".  the posted snippets are
fine as far as test-cases go.  (-; but this is not "official" policy.)

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Re: Continuations: possible newbie question
@ 2002-12-18 17:27 Thien-Thi Nguyen
  2002-12-18 18:14 ` Matt Hellige
  0 siblings, 1 reply; 10+ messages in thread
From: Thien-Thi Nguyen @ 2002-12-18 17:27 UTC (permalink / raw
  Cc: guile-user

   From: Matt Hellige <matt@immute.net>
   Date: Tue, 17 Dec 2002 18:14:25 -0600

   is this due to a bug in guile,

perhaps.  here is what i see:

guile> (version)
"1.4.1.93"
guile> (load "cwcc.scm")		; as posted
guile> (exec-binding bind)
"escaped"
guile> (done-reading "hi")
hi
guile> 

   or to my abuse of continuations?

continuations are basically a sanctioned control-flow abuse mechanism,
so it is all just a matter of degree.  i have been happy not to use them
except as escapes, in my code.  in one gig i used them -- guile 1.3.4, i
believe -- as co-routines (like your example) but that was more to
impress the Boss (and drag myself out of ignorance ;-) than anything.

   another way to do what I'm trying to do?

probably you can continue your explorations in this vein w/ more
debugging support: use `trace' and `pk' to determine where things go
wrong, and/or use a guile version that behaves as you expect.

all other ways essentially devolve into using continuations.

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 10+ messages in thread
* Continuations: possible newbie question
@ 2002-12-18  0:14 Matt Hellige
  0 siblings, 0 replies; 10+ messages in thread
From: Matt Hellige @ 2002-12-18  0:14 UTC (permalink / raw


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")
    (((()) #<eval-closure 40278f60>))
    guile> 
    guile> 
    guile> (exec-binding bind)
    "escaped"
    guile> (done-reading "hi")
    (#<unknown-immediate 0xaa8dc> #<smob 4001f000> . #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)
    <unnamed port>: In procedure gsubr-apply in expression (throw (quote
    interact)):
    <unnamed port>: 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2002-12-26 23:08 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-18 18:42 Continuations: possible newbie question Thien-Thi Nguyen
2002-12-26 21:30 ` Found a bug in guile 1.6.0 Roland Orre
2002-12-26 23:08   ` Marius Vollmer
  -- strict thread matches above, loose matches on Subject: below --
2002-12-18 17:27 Continuations: possible newbie question Thien-Thi Nguyen
2002-12-18 18:14 ` Matt Hellige
2002-12-18 20:04   ` Neil Jerram
2002-12-18 23:51     ` Matt Hellige
2002-12-19  0:41       ` Marius Vollmer
2002-12-19  2:42         ` Matt Hellige
2002-12-18  0:14 Matt Hellige

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).