variable tracing question
 
Post new topic   Reply to topic    Hawkee.com Forum Index -> TCL Scripting
 
fernando.vs  -  Sat Apr 02, 2011 12:03 pm Reply with quote
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.
Display posts from previous:   
Post new topic   Reply to topic    Hawkee.com Forum Index -> TCL Scripting All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.