Version 0 of NRE: Coroutines in 8.6

Updated 2008-10-22 20:13:35 by cleverly

The second talk in Miguel Sofer's NRE series at Tcl2008, following up on NRE: the non-recursive engine in Tcl 8.6:

Coroutines--what?

  • A computation that can be suspended and resumed on demand or killed while suspended
  • A tool to create generators
  • A tool to simplify the coding of event-based programs
  • A tool to enable cooperative multitasking within a single interp, without OS support

TIP #328 specifies three new commands: coroutine, yield, and info coroutine. [coroutine] is evaluated equivalently to uplevel #0 [list cmd ?arg ...?]. [yield] suspends operation. Walked through an example from the tip.

[yield] returns twice: when yielding (caller reeives a return value from the yielding coroutine); when resuming coroutine sees the [yield] command returning. [cmdName] is "garbage collected". Example at http://msofer.com:8080/wiki?name=Coroutines

Went through the wiki page Coroutines for event-based programming showing converting a console application to a GUI.