confusing unset/upvar documentation
Closed / Invalid1242314fffffffffffffffffffffffffffffffffCreated 21 years agoUpdated 21 years ago
Descriptionplain2005-07-21 14:03:14
Sorry but I cannot test this now with newer releases.
From the [upvar] manual page:
"If an upvar variable is unset [...] the unset
operation
affects the variable it is linked to, not the
upvar
variable. There is no way to unset an upvar
variable
except by exiting the procedure in which it is
defined."
Playng with tclsh:
/usr/local/bin/tclsh 8.4 (marco) % set tcl_version
8.4
/usr/local/bin/tclsh 8.4 (marco) % info patchlevel
8.4.8
/usr/local/bin/tclsh 8.4 (marco) % set a 1
1
/usr/local/bin/tclsh 8.4 (marco) % proc p {} { upvar a
b ; puts $b ; unset b }
/usr/local/bin/tclsh 8.4 (marco) % p
1
/usr/local/bin/tclsh 8.4 (marco) % set a
can't read "a": no such variable
/usr/local/bin/tclsh 8.4 (marco) %
Ciao.
msoferplain2005-07-21 22:13:55
Logged In: YES user_id=148712 The language may be somewhat confusing ... but what you see is precisely what is documented. When you do 'upvar a b', the docs call b 'the upvar variable' (ie, the variable created by the upvar command); it is linked to the variable a. Hence, the docs say that 'unset b' actually unsets a, just as you observed. I'll leave this open and consider it a documentation bug: maybe we can come up with a description less likely to confuse, or add an example.
marcomaggiplain2005-07-27 02:15:28
Logged In: YES
user_id=727156
Fine. I agree with the documentation bug and the need for
the example. Maybe the code that I used to show it is enough.
I propose two changes:
"If an upvar variable is unset (e.g. x in add2 above), the
unset operation affects the variable it is linked to,
not the
upvar variable."
should be:
"If the unset command is invoked with an upvar variable
as argument (e.g. x in add2 above), the unset operation
affects both the variable it is linked to, and the upvar
variable."
The phrase:
"There is no way to unset an upvar variable except
by exiting the procedure in which it is defined.
However, it is possible to retarget an upvar variable
by executing another upvar command."
should be:
"There is no way to unlink an upvar variable from the
linked one without unsetting both, except by exiting the
procedure in which it is defined or by retargeting the
upvar variable by executing another upvar command."
msoferplain2006-03-11 21:12:36
Logged In: YES user_id=148712 Revisiting after such a long time ... I do not agree with your reformulations: the unset operation does not affect the upvar variable, and it does not destroy the link. It just unsets the variable to which the link was created. Witness % set x 1 1 % upvar 0 x y % set y 1 % unset y % set x can't read "x": no such variable % set y 2 2 % set x 2
sf-robotplain2006-03-26 10:21:10
Logged In: YES user_id=1312539 This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker).
sf-robot Ticket [1242314fff]: 2 changes
[History diff]2006-03-26 10:21:11
Log in (anonymous is fine) to add a comment.