Continuations in D?
ian at locut.us
ian at locut.us
Tue Feb 21 20:35:50 PST 2006
In article <dtclr2$1vgq$1 at digitaldaemon.com>, Unknown W. Brackets says...
>Please forgive my ignorance; what is a continuation or where can I read
>about it?
Continuations can be quite confusing, depending on how they are explained. The
"correct" explanation
is quite difficult to understand.
A simpler way is to think of a continuation as a frozen thread, although
typically they use far fewer
resources than an actual frozen thread. It allows you to program in a very
"thread heavy" way, but
without the overhead that would typically imply.
Continuations are useful in situations where you might otherwise use a lot of
threads, but where those
threads spend most of their time waiting for things to happen. Many networked
applications fall into
this category, indeed, what initially got me interested in continuations was my
work on P2P
architectures.
The alternative to continuations is to use an event-based, or callback-based
architecture, but this can
quickly degenerate into spaghetti code (been there, done that).
Continuations are present in some of the more academic languages, including
Scheme, and some
dialects of ML. Ruby also has them, as does Stackless Python. They can also be
simulated in C using
some rather scary low-level hacking (someone else alluded to this in this
thread), but that isn't for the
faint of heart, nor is it cross-platform. There are also some kludges to
achieve continuations in Java,
but they aren't very pretty or efficient.
Support for continuations in D would make it a prime candidate for anyone
interested in implementing
network-based stuff in an efficient language, especially P2P stuff.
Ian.
More information about the Digitalmars-d
mailing list