Posted to tcl by miguel at Tue Aug 12 21:34:27 GMT 2008view raw
- % set lambda
- {{start 1} {stop 4}} {
- # init
- set i $start
- set imax $stop
- yield starting
- while {$i < $imax} {
- set stop [yield [expr {$i*$stop}]]
- incr i
- }
- puts exiting!
- return [expr {$i*$stop}]
- }
- % coroutine foo ::apply $lambda
- starting
- % foo 2
- 4
- % foo 11
- 22
- % foo 5
- 15
- % foo 1
- exiting!
- 4
- % foo 1
- invalid command name "foo"