If you don’t have it already, I would highly recommend the Brent Welch book “Practical Programming in TCL and TK”. I have the Fourth Edition.
http://www.amazon.com/Practical-Programming-Tcl-Tk-4th/dp/0130385603
ISBN 0-13-038560-3
There is a whole chapter on Namespaces.
A quick sketch on namespaces with regard to your variable issue is that namespaces provide a hierarchical set of global variable references.
Say we wanted a variable named “common”. We can put that variable in a namespace for access by any proc that runs in that interpreter.
(In Cloverleaf, each UPOC in an engine has a common interpreter.)
You initialize by using the incantation:
namespace eval MySpace {
variable common
}
You can then use the global variable in any of the procs that run in that UPOC thusly,
set MySpace::common “MyScalar”
puts $MySpace::common
You can also create procs in namespaces and call them from any downstream proc as well. They are an indispensable utility for advanced implementation.
I realize that this involves renaming variables, but using namespaces is well worth the investment.