Tutorial by Examples

The command set is used to assign values in Tcl. When it is called with two arguments in the following manner, % set tempVar "This is a string." This is a string. it places the second argument ("This is a string.") in the memory space referenced by the first argument (tempVa...
set alpha 1 proc myproc {} { puts $alpha } myproc This code doesn't work because the two alphas are in different scopes. The command set alpha 1 creates a variable in the global scope (which makes it a global variable). The command puts $alpha is executed in a scope that is created ...
In order to print the value of a variable such as, set tempVar "This is a string." The argument in the puts statement is preceded by a $ sign, which tells Tcl to use the value of the variable. % set tempVar "This is a string." This is a string. % puts $tempVar This is a s...
set can also be invoked with just one argument. When called with just one argument, it returns the contents of that argument. % set x 235 235 % set x 235
The unset command is used to remove one or more variables. unset ?-nocomplain? ?--? ?name name name name? Each name is a variable name specified in any of the ways acceptable to the set command. If a name refers to an element of an array then that element is removed without affecting the rema...
The variable command ensures that a given namespace variable is created. Until a value is assigned to it, the variable's value is undefined: namespace eval mynamespace { variable alpha set alpha 0 } The variable can be accessed from outside the namespace (from anywhere, in fact) by at...

Page 1 of 1