fernandovs
Technical User
hi,
I'm kinda new in TCL im working right now with the "Tcl and the Tk toolkit book" 2nd edition. I'm checking about variable tracing right now, and I fount this example:
trace add variable size write forceint
proc forceint {name element op} {
upvar 1 $name x ${name}_old x_old
if {[regexp {^\d+$} $x]} {
set x $x_old
error "value must be a positive integer"
}
set x_old $x
}
According to the book this script is going to set up a read-only variable, however it is not working for me, when i run this script on TCL 8.5 on linux i have:
% set size 47
can't set "size": can't read "x_old": no such variable
I have some serious doubts about this variable x ${name}_old, since a write trace is invoked after the variable's value is changed, i don't think that this _old variable exists and of course the script wouldn't work.
Please tell me your thoughts about this script and if it doesn't work is there any workaround to implement this read-only variable in TCL with tracing?
thanks all for your help.
I'm kinda new in TCL im working right now with the "Tcl and the Tk toolkit book" 2nd edition. I'm checking about variable tracing right now, and I fount this example:
trace add variable size write forceint
proc forceint {name element op} {
upvar 1 $name x ${name}_old x_old
if {[regexp {^\d+$} $x]} {
set x $x_old
error "value must be a positive integer"
}
set x_old $x
}
According to the book this script is going to set up a read-only variable, however it is not working for me, when i run this script on TCL 8.5 on linux i have:
% set size 47
can't set "size": can't read "x_old": no such variable
I have some serious doubts about this variable x ${name}_old, since a write trace is invoked after the variable's value is changed, i don't think that this _old variable exists and of course the script wouldn't work.
Please tell me your thoughts about this script and if it doesn't work is there any workaround to implement this read-only variable in TCL with tracing?
thanks all for your help.