====== # returns an unused procedure name proc gensym {prefix} { tailcall apply {{prefix} { string cat $prefix[llength [info commands $prefix*]] }} $prefix } # creates an anonymous coroutine proc go {cmd args} { set name [gensym goro#] coroutine $name $cmd {*}$args return $name } ====== Credit for the above code goes to [aspect]. The odd construct with `tailcall apply` is so that [info commands] will be executed in the caller's namespace. [MS] finds that this construct has a big problem: name reuse. Some code could be holding onto a coro handle, and wanting to find out if it still exists via [[info command]] (or just waiting to error out, intentionally or not). If the coro exited and a new one was created with the same name, chaos could ensue ... So my proposal is to either use a global counter (possibly in a namespace). If we really cannot live with a global var, we could do: ====== coroutine gensym apply [list prefix { while 1 { yield $prefix[incr counter] } } ====== <>Concurrency