[Xotcl] coroutines

Victor Mayevski vitick at gmail.com
Wed Sep 29 19:58:55 CEST 2010


Thank you Gustaf, 

Part of my original question, which still stands, was "would it be worth it?"

It seems that the example you provided can be done with XOTcl alone, no need for coroutine. Is there any case where coroutine would actually give some extra power to XOTcl? Forgive me, I am not a C programmer so the concept of NRE or stackless TCL is a little foggy to me. 



----- Original Message -----
From: "Gustaf Neumann" <neumann at wu-wien.ac.at>
To: xotcl at alice.wu-wien.ac.at
Sent: Tuesday, September 28, 2010 2:49:06 AM GMT -08:00 US/Canada Pacific
Subject: Re: [Xotcl] coroutines

  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
}

_______________________________________________
Xotcl mailing list
Xotcl at alice.wu-wien.ac.at
http://alice.wu-wien.ac.at/mailman/listinfo/xotcl


More information about the Xotcl mailing list