[pypy-dev] Stackless PyPy mini sprint 2007

Armin Rigo arigo at tunes.org
Mon Sep 17 12:31:23 CEST 2007

Hi Erik,

On Mon, Sep 17, 2007 at 03:00:51AM +0200, Erik Gorset wrote:
> Btw, it's possible to simulate some of call/cc's behavior using
> _stackless.fork() (I have a play-implementation lying around here
> somewhere). But it has several issues. The biggest one is that fork()
> actually copies some of the objects found on the stack. It's been
> a while since I've played around with cloneable and fork, so maybe
> this has been fixed.

A deep issue with continuations in a language like Python is that there
is no single best definition of what it should capture and what it
should not.  If you think about what you would like to occur when you
capture a continuation or fork a coroutine, then you'll notice that you
actually want some objects on the stack to be duplicated, and others

For example, in:

    def f(n):
        return [x*x for x in range(n)]

which, remember, is equivalent to:

    def f(n):
        lst = []
        for x in range(n):
        return lst

if we pause this function in the middle of the loop and fork it, then it
feels "right" to duplicate the list -- otherwise both the original and
the copy will append the remaining items into the same list, resulting
in a single list with more than n elements.

In essence, it seems to me that both forking and full continuations
should not be part of the core of a language, for the same reasons as
pickling -- in my own experience at least, more than half of the time
"pickle" doesn't capture enough or capture too much.  There is no single
best solution.

A bientot,


More information about the Pypy-dev mailing list