Documentation of "upvar" command
Closed / Invalid1768830fffffffffffffffffffffffffffffffffCreated 19 years agoUpdated 19 years ago
Descriptionplain2007-08-06 21:26:48
The following is taken from the online description of the "upvar" command which was generated from Tcl CVS HEAD.
SYNOPSIS
upvar ?level? otherVar myVar ?otherVar myVar ...?
DESCRIPTION
The variable named by otherVar need not exist at the time of the call; it will be created the first time myVar is referenced, just like an ordinary variable.
The statement that "otherVar" will be created in case of a call to "myVar" is confusing and probably wrong.
In case of a call to "myVar" or if used the first time and if the referenced "otherVar" does not exist a error will be raised by the tcl interpreter that "myVar" can't be read because it is not existing. This is because "myVar" references to nothing.
The following example will illustrate this with the second procedure call:
#!/usr/bin/tclsh
proc CallOn { variable } {
upvar $variable variableRef
puts "variable=$variable"
puts "variableRef=$variableRef"
}
set v "Test"
CallOn v ; # by name
CallOn $v ; # by value
msoferplain2007-08-07 04:47:27
Logged In: YES user_id=148712 Originator: NO User confusion: the variable exists but is undefined, its value cannot be retrieved until it has one.
Log in (anonymous is fine) to add a comment.