PDA

View Full Version : stackless python


kmj
10-21-2002, 12:53 PM
wondering if anyone's looked into this...

http://www.stackless.com/spcpaper.htm#_Toc470444054

I admit I haven't spent a great deal of time trying to understand, it; but I get that the purpose for stackless python is to allow for the use of "continuations"... the paper doesn't seem to explain what the practical benefits of continuations are. I was wondering if anyone out there could enlighten me on why exactly a person would want to use stackless python.

jemfinch
10-21-2002, 03:10 PM
Continuations are a very powerful (some say too powerful) control construct. Practically all other constructs can be implemented via continuations, but in particular, the constructs that can be implemented easily and efficiently with continuations are generators, coroutines, exceptions, and microthreads (also known as "green" threads).

A continuation is basically the rest of the program at any given point. If I have a program like this:


x = y
a = b
c = d


Then the continuation after the first statement is "a = b; c = d" and after the second statement is "c = d." Continuations are re-entrant; if a language provides the facilities necessary to "capture" the current continuation, you can later "pick up where you left off" at that point.

That's about the extent of my knowledge. I haven't used continuations much, but, for instance, and entire Concurrency library (threads, etc.) in SML has been written for SML/NJ because SML/NJ provides continuations.

Jeremy

kmj
10-21-2002, 04:57 PM
so, uh.. what's the difference between a continuation and a goto? :)

Strike
10-21-2002, 05:56 PM
kmj: I think it's kind of like a state machine of sorts (which is how I think of generators). Continuations (as I understand the explanation above) seem to be a specified state that you can jump back to later - everything will be as it was when you first arrived there. Brush up on your DFA's and NFA's to realize how powerful that can be :)