[Stackless] On continuations

Christian Tismer tismer at stackless.com
Tue Mar 16 17:57:43 CET 2004


Andy Sy wrote:

> Anyone aware that Ruby now has continuations?
> 
> http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_continuation.html
> http://www.rubygarden.org/ruby?Continuations
> http://www.crankycoder.com/archives/000138.html

No, and I'm quite astonished. I learned my lesson
about continuations, been there, was burnt, don't
wanna go again.
Without continuations, Stackless might be in the
Python core, today.

> Anyway, I thought I might revisit the old Stackless with continuations
> since I never really got my understanding down pat (although I felt I had
> at least partially understood how call/cc worked under Scheme, and could've
> sworn I had been able to wrap my brain somewhat around Nathaniel Gray's
> tutorial...)
> 
> Revising the original SPC paper reveals that the culprit lies with the
> very first example in the original SPC paper:
> 
> def looptest(n):
>     this = continuation.current()
>     k = this.update(n)
>       # continuation at "="
>     if k:
>         this(k-1)
>         # resuming at "="
>     else:
>         del this.link
> 
> 
> The problem is that this.update(), this() and this.link
> were never really explained properly when they were presented.
> Further, I believe the choice of how n and k were used confuses
> instead of enlightens the reader.

The problem with this example was that update changes the
continuation to point to the right place in the program.
This was a technical problem. Ruby can do it better,
since it has a language construct for this.
Later on, I discovered that it is much simpler and doesn't
need such tricks, if you leave the function at the same
time when you save the continuation.
The function for that was return_current, and it was used in
almost all later implementation, like microthreads.

The problem with the "current" continuation is that
it is out of date, all the time, and therefore I do not
recommend to beginners to refer to current at all.

You might do something like this, still ugly:

def looptest():
     # do some initialisation
     # ...
     this, k = continuation.return_current()
     if k:
         print k
         this(this, k-1)
         # resuming at "="

x = looptest
x(x, 10)

> I think the first example for an absolute beginner should go something
> like the following:
> 
> "A continuation is like a bookmark."

...

This is all Stackless 1.0 stuff. I abandoned everything about
continuations in spring 2002, and this paper is out of date.
I have no plans of reviving full continuations at any time
in the future, nor do I want do write another paper on them
or educate people how to use them.

If Stackless uses continuations (what does that mean? :-) at
all today, then you might think of mutable continuations
or one-shot continuations, which actually are not really
something special.

cheers - chris

-- 
Christian Tismer             :^)   <mailto:tismer at stackless.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a     :    *Starship* http://starship.python.net/
14109 Berlin                 :     PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34  home +49 30 802 86 56  mobile +49 173 24 18 776
PGP 0x57F3BF04       9064 F4E1 D754 C2FF 1619  305B C09C 5A3B 57F3 BF04
      whom do you want to sponsor today?   http://www.stackless.com/


_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list