Posted to tcl by kyak at Thu Nov 08 18:16:02 GMT 2018view pretty
proc do_stuff {args} { if 1 $args # simulate blocking (e.g. in a http request) #after 2000 # repeat this in 1 second: after 1000 [list do_stuff $args] } do_stuff puts "some stuff" do_stuff puts "some other stuff" after 10000 {set forever stop} vwait forever
Comments
Posted by avl at Mon Nov 12 12:32:44 GMT 2018 [text] [code]
inside the first call, args is, as if you had set it inside the proc as: set args {puts "some stuff"} ; that is what works with "if 1", which is almost equivalent to "eval". but then you create an after script that calls do_stuff with a single argument, rather than with separate arguments. line 6 should read: after 1000 [list do_stuff {*}$args] or alternatively: after 1000 [linsert $args 0 do_stuff] That said, it is not recommended to pass a script as separate words to a command. an even better aproach might be to turn "args" to a different name, and kick it off with do_stuff {puts "some stuff"}