a simple example of Stackless Python

Evan Simpson evan at 4-am.com
Mon Oct 30 19:12:37 EST 2000


"June Kim" <junaftnoon at nospamplzyahoo.com> wrote in message
news:8tjrn2$esm$1 at news.nuri.net...
> It seems like there are few people who understand Stackless Python
> and the stuffs, and I'm not one of them. Can anyone explain me
> this simple code? The paper was not very helpful for me to understand.

I'll give it a shot. "this = continuation.current()" creates a continuation
object, and "this.update(n)" does two things: First, it updates the
continuation object so that calling it will cause program execution to
continue at that line, as though "this.update(n)" had just returned the
value passed in the call.  Second, it evaluates to n, so that the line acts
as though it were "k = n".

Thus, "this(k-1)"  jumps to the "k = this.update(n)" line and makes it act
as though it were "k = k-1".  It means "continue at the point just after we
were updated, with k-1 on top of the stack".

The whole function behaves exactly like:

k = n
while k:
  k = k-1

...and demonstrates how a continuation can be used to construct a simple
loop.


--
Cheers,

Evan @ digicool & 4-am





More information about the Python-list mailing list