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 rmax
15 days ago
tcl by oldlaptop
16 days ago
tcl by schelte
16 days ago
tcl by Bradipo
29 days ago
tcl by kbk
39 days ago
tcl by oldlaptop
42 days ago
tcl by Julian Noble
48 days ago
tcl by oldlaptop
72 days ago
tcl by dandyn
76 days ago
tcl by oldlaptop
79 days ago
Submit
New paste
Documentation
From Jabber