Is it possible to declare a static variable in Tcl?
I use a certain function to catch unknown command errors, and I want it to print an error message on the first appearance of an unknown command - so I need to keep something like a static list inside the proc
. Is that possible?
Or you can just use a straight global variable:
set varList {}
proc useCount {value} {
global varList ;
lappend varList $value
}
useCount One
useCount Two
puts $varList
No. But you can use a global (usually namespaced) array indexed by proc name for instance:
namespace eval foo {
variable statics
array set statics {}
}
...
proc ::foo::bar args {
variable statics
upvar 0 statics([lindex [info level 0] 0]) myvar
# use myvar
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With