Prev: How to detect if event loop is running ?
Next: regexp
From: Dean Chao on 3 Sep 2009 12:57 Hi guys, How to use global variable as the default value for procedure parameter. I.e., proc foo {{bar $var}} { puts $bar } set var "hello world!" foo When I do this, stdout prints $var instead of "hello world!" thx Dean
From: Jeff Godfrey on 3 Sep 2009 13:04 Dean Chao wrote: > Hi guys, > > How to use global variable as the default value for procedure parameter. > I.e., > > > proc foo {{bar $var}} { > puts $bar > } > > set var "hello world!" > foo > > > > > When I do this, stdout prints $var instead of "hello world!" How about something like... proc foo {{bar ""}} { if {$bar eq ""} { set bar $::var } puts $bar } Jeff
From: rf on 3 Sep 2009 13:11 set var default # set the default value of bar to the actual value of var proc foo [list [list bar $var]] {return $bar} Roland
From: rf on 3 Sep 2009 13:34 to reflect changes to var: proc foo [list [list x var]] { upvar $x z puts $z }
From: Cameron Laird on 3 Sep 2009 14:02
In article <h7osv7$sve$1(a)news.eternal-september.org>, Jeff Godfrey <jeff_godfrey(a)pobox.com> wrote: >Dean Chao wrote: >> Hi guys, >> >> How to use global variable as the default value for procedure parameter. >> I.e., >> >> >> proc foo {{bar $var}} { >> puts $bar >> } >> >> set var "hello world!" >> foo >> >> >> >> >> When I do this, stdout prints $var instead of "hello world!" > >How about something like... > >proc foo {{bar ""}} { > if {$bar eq ""} { > set bar $::var > } > puts $bar >} > >Jeff OR proc foo [list [list bar $::var]] { do_the_real_work_of_foo $bar } |