Continuations and threads (was Re: Iterators & generators)

Moshe Zadka moshez at math.huji.ac.il
Fri Feb 18 06:23:49 EST 2000


On Fri, 18 Feb 2000, Toby Dickenson wrote:

> What are the implications for the continuation-naive in a
> post-stackless world. What about functions such as...
> 
> def x():
>     before()
>     try:
>         y()
>     finally:
>         after()

The Scheme world calls this dynamic-wind. To be concrete

(dynamic-wind before thunk after), in the absence of continuations, the
same as

(before)
(thunk)
(after)

However, in the presence of continuation, it is guranteed whenever
"thunk" is entered execution, "before" is called, and whenever "thunk"
stops execution, "after" is called.

Here's a quote from R^5RS:

(dynamic extent are those times protected by before/after):

        * The dynamic extent is entered when execution of the body of
          the called procedure begins.

        * The dynamic extent is also entered when execution is not
          within the dynamic extent and a continuation is invoked that
          was captured (using `call-with-current-continuation') during
          the dynamic extent.

        * It is exited when the called procedure returns.

        * It is also exited when execution is within the dynamic extent
          and a continuation is invoked that was captured while not
          within the dynamic extent.

Don't even think about dynamic-wind within dynamic-wind
--
Moshe Zadka <mzadka at geocities.com>. 
INTERNET: Learn what you know.
Share what you don't.





More information about the Python-list mailing list