$var and ${var} are the same.
You use the {} method, when you need to place text together, eg.
Code: Select all
set var "$varthis sting"
set var "${var}this string"
YOu can see clearly hwo this is used, to provide exact control over names. It is also needed in situation where you use a - in the variable name. EG.
Code: Select all
set this-var 15
set thatvar 20
expr ${this-var}-$thatvar
Without it, you can see the issue. This - issue is a little more deeper than this, and you should use {} whenever there is a - in the var name.
The :: is to do with namespaces. I sugest reading up about namespaces in the Tcl man pages, but you should see hwo this works.
At any 1 time, you can access a command or variable from any namespace, using the fully qualified name. This is irispective of the command or variable scope.
The global namespace is called ::. That should give you a hint as to why you use ::.
With variable scope, you have to import a global variable to use its existing value
Code: Select all
set a "test"
proc test {} {
global a
puts stdout $a
}
Because usign the fully qualified name doesn't care about scope, you don't need to import it.
Code: Select all
set a "test"
proc test {} {
puts stdout $::a
}
The added benefit of this is long winded code segments. You can clearly distinguish between global and local variables, and it saves jumping to the start of the proc, just to import a variable.