Menu

#3756 Documentation of "upvar" command

obsolete: 8.5a7
closed-invalid
5
2007-08-06
2007-08-06
Anonymous
No

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

Discussion

  • miguel sofer

    miguel sofer - 2007-08-06

    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.

     
  • miguel sofer

    miguel sofer - 2007-08-06
    • status: open --> closed-invalid