[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: manipulating continuations
From: |
Andy Wingo |
Subject: |
Re: manipulating continuations |
Date: |
Sat, 12 Feb 2011 16:43:59 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
Hi Thomas,
On Sat 12 Feb 2011 15:10, Thomas Girod <address@hidden> writes:
> (define (foo)
> (call/cc
> (lambda (return)
> (display "first part")
> (newline)
> (call/cc
> (lambda (cont)
> (return cont)))
> (display "second part")
> (newline))))
>
> guile> (define c (foo))
> first part
> guile> (c)
> second part
>
> yay, it works. But now, what if I want to run the continuation directly,
> rather than storing it and calling it later ? This is what I get:
>
> guile> ((foo))
> first part
> second part
>
> Backtrace:
> In current input:
> 15: 0* [#<unspecified>]
In this expression, `foo' has returned twice. The first time it
returned a continuation, which was applied. The second time it returned
whatever `newline' returned: the unspecified value. Applying the
unspecified value failed.
If you use Guile 1.9/2.0, partial continuations behave more in the way
you were thinking of:
(use-modules (ice-9 control))
(define (foo)
(% (begin
(display "first part\n")
(abort)
(display "second part\n"))
(lambda (cont)
;; abort jumps back here, to the handler. return the partial
;; continuation.
cont)))
scheme@(guile-user)> (foo)
first part
$1 = #<partial-continuation 29dede0>
scheme@(guile-user)> ($1)
second part
scheme@(guile-user)> ((foo))
first part
second part
scheme@(guile-user)>
Have fun with Guile,
Andy
--
http://wingolog.org/