Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/Variables/Tcl/variables.tcl
Normal file
23
Task/Variables/Tcl/variables.tcl
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
namespace eval foo {
|
||||
# Define a procedure with two formal arguments; they are local variables
|
||||
proc bar {callerVarName argumentVar} {
|
||||
### Associate some non-local variables with the procedure
|
||||
global globalVar; # Variable in global namespace
|
||||
variable namespaceVar; # Variable in local (::foo) namespace
|
||||
# Access to variable in caller's context; may be local or global
|
||||
upvar 1 callerVarName callerVar
|
||||
|
||||
### Reading a variable uses the same syntax in all cases
|
||||
puts "caller's var has $callerVar"
|
||||
# But global and namespace vars can be accessed by using qualified names
|
||||
puts "global var has $globalVar which is $::globalVar"
|
||||
|
||||
### Writing a variable has no special syntax
|
||||
### but [set] is by far the most common command for writing
|
||||
set namespaceVar $globalVar
|
||||
incr globalVar
|
||||
|
||||
### Destroying a variable is done like this
|
||||
unset argumentVar
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue