
On 18 Dec 2008, at 11:26 am, Andrew Coppin wrote:
(Also, "coroutines"? Seriously? That's hardly an obscure term in programming circles.)
Well now, I'm curios. I've been writing computer programs since I was 9 years old. I hold a diploma *and* an honours degree in computer science. And I have never even *heard* of a coroutine. To this day I still don't know what it means. I rather suspect I'm not the only "programmer" on earth who finds themselves in this position. ;-)
Shame on you for not reading Knuth's "The Art of Computer Programming", Volume 1, "Fundamental Algorithms". The then available three volumes of TAOCP "were named among the best twelve physical-science monographs of the century by American Scientist" "at the end of 1999". (Fasicles 0, 2, 3, and 4 of volume 4 are now available, and parts of fasicle 1 are on-line. Hooray hooray!) Quoting the first two paragraphs of the Wikipedia entry: "In computer science, coroutines are program components that generalize subroutines to allow multiple entry points for suspending and resuming of execution at certain locations. Coroutines are well- suited for implementing more familiar program components such as cooperative tasks, iterators, infinite lists and pipes. The term "coroutine" was originated by Melvin Conway in his seminal 1963 paper.[1]" So "coroutine" has been standard hacker-type programming terminology since 1963. I was able to use coroutines in Burroughs Extended Algol (designed in the mid to late 60s), Simula 67, and Interlisp-D (80s). Current languages supporting them include (thanks, Wikipedia) Lua, Limbo, JavaScript, Python, and Ruby. Since anything with continuations can do coroutines, we add Scheme and SML/NJ. Sather's iterators may be a more familiar form of coroutine. You will commonly find something like a "yield e" statement that reports the value of e to the caller without actually returning, and "resume c" that resumes a coroutine to get the next value.