tcl Procedure arguments A procedure that accepts a name/reference to a variable


Example

proc myproc {varName alpha beta} {
    upvar 1 $varName var
    set var [expr {$var * $alpha + $beta}]
}
set foo 1
myproc foo 10 5
puts $foo
# => 15

In this particular case, the procedure is given the name of a variable in the current scope. Inside a Tcl procedure, such variables aren't automatically visible, but the upvar command can create an alias for a variable from another stack level: 1 means the caller's stack level, #0 means the global level, etc. In this case, the stack level 1 and the name foo (from the parameter variable varName) lets upvar find that variable and create an alias called var. Every read or write operation on var also happens to foo in the caller's stack level.