[Xotcl] coroutines

Gustaf Neumann neumann at wu-wien.ac.at
Tue Sep 28 11:49:06 CEST 2010


  On 02.09.10 07:28, Victor Mayevski wrote:
> I am wondering if it will be possible to somehow implement coroutines in XOTcl? Is it feasible? Would it be worth it?
Sorry for the late answer. With XOTcl 1.6.* there is no 
special support
for coroutines (one can certainly create Tcl-coroutines and 
use it).

With 2.0 one can write object oriented coroutines.
The new regression test contains already the classical 
number generator
example based on coroutines (see below).

-gustaf neumann

=========================================================
Test case number-generator {

   Object create numbers {

     # set instance variable used in coroutine
     set :delta 2

     :public method ++ {} {
       yield
       set i 0
       while 1 {
         yield $i
         incr i ${:delta}
       }
     }
   }

   # create coroutine
   coroutine nextNumber numbers ++
   set ::j 0

   # use coroutine
   for {set i 0} {$i < 10} {incr i} {
     incr ::j [nextNumber]
   }

   # remove coroutine
   rename nextNumber {}

   ? {set ::j} 90
}



More information about the Xotcl mailing list