Continuations and threads (was Re: Iterators & generators)
Harald Hanche-Olsen
hanche at math.ntnu.no
Fri Feb 18 22:12:35 EST 2000
+ "Samuel A. Falvo II" <kc5tja at armored.net>:
| On Fri, 18 Feb 2000, Moshe Zadka wrote:
|
| > with the value "x". On the other hand, if the function which was given to
| > call/cc returns with the value "x", the function which called call/cc also
| > thinks call/cc returned with value "x".
|
| OK, so it's _exactly_ like setjmp/longjmp then -- a threads package. :)
No, no, no, NO! Oh well, OK, maybe a bit, if you were allowed to
longjmp() to someplace *after* the function doing the corresponding
setjmp() had exited, thus magically reviving the function doing the
longjmp() in the first place.
But you have caught on to an important point: Call/cc has uses which
generalize those of setjmp/longjmp, or throw/catch in Lisp. This use
is called backward continuations, and are easy to implement. If you
want to implement the full power of continuations in a stack based
language, you wind up doing dirty tricks like storing away a copy of
the call stack whenever someone does a call/cc.
possible-but-expensive-ly y'rs,
--
* Harald Hanche-Olsen <URL:http://www.math.ntnu.no/~hanche/>
- "There arises from a bad and unapt formation of words
a wonderful obstruction to the mind." - Francis Bacon
More information about the Python-list
mailing list