Posted to tcl by miguel at Tue Aug 12 21:34:27 GMT 2008view raw

  1. % set lambda
  2. {{start 1} {stop 4}} {
  3. # init
  4. set i $start
  5. set imax $stop
  6. yield starting
  7.  
  8. while {$i < $imax} {
  9. set stop [yield [expr {$i*$stop}]]
  10. incr i
  11. }
  12. puts exiting!
  13. return [expr {$i*$stop}]
  14. }
  15. % coroutine foo ::apply $lambda
  16. starting
  17. % foo 2
  18. 4
  19. % foo 11
  20. 22
  21. % foo 5
  22. 15
  23. % foo 1
  24. exiting!
  25. 4
  26. % foo 1
  27. invalid command name "foo"