have [yield] return the args from subsequent coroutine invocations?
Posted to
tcl
by kbk at Fri Jul 18 20:49:44 GMT 2008
view raw
coroutine adder {n} {
set
sum
$n
while
{1} {
incr
sum [
lindex
[yield
$sum
] 0]
}
}
puts
[adder 1]; # prints 1
puts
[adder 2]; # prints 3
puts
[adder 3]; # prints 6
Recent Posts
tcl by oldlaptop
8 days ago
tcl by oldlaptop
8 days ago
tcl by mookie
13 days ago
tcl by mookie
13 days ago
tcl by georgtree
15 days ago
tcl by georgtree
15 days ago
tcl by schelte
30 days ago
tcl by emiliano
37 days ago
tcl by fvogel
37 days ago
tcl by emiliano
37 days ago
Submit
New paste
Documentation
From Jabber