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 cgm
3 days ago
tcl by cgm
3 days ago
tcl by alan
11 days ago
tcl by mookie
33 days ago
tcl by mookie
33 days ago
tcl by mookie
33 days ago
tcl by schelte
35 days ago
tcl by oldlaptop
47 days ago
tcl by oldlaptop
51 days ago
tcl by mookie
51 days ago
Submit
New paste
Documentation
From Jabber