the syntax of upvar is:
upvar ?level? varName localvar
example:#!/usr/bin/tcl
proc swap { x y} {
upvar x a
upvar y b
set tmp $a
set a $b
set b $tmp
}
set x 10
set y 5
swap x y
puts "x is $x"
puts "y is $y"
proc swap { x y} {
upvar x a
upvar y b
set tmp $a
set a $b
set b $tmp
}
set x 10
set y 5
swap x y
puts "x is $x"
puts "y is $y"
result:
x is 5
y is 10
y is 10
0 comments:
发表评论