GPS Oct 16, 2003 - It occurred to me that I might accidentally set the wrong variable (it has happened in the past), and it could cause me to have a nasty debug session, so I decided to come up with a proc that sets a variable but returns an error if it doesn't exist.
proc ?set {v_name val} { upvar $v_name v if {![info exists v]} { return -code error "expected $v_name to exist!" } set v $val } ;# GPS
Here is a log demonstrating usage:
% ?set foo bar expected foo to exist! % set foo abc abc % ?set foo bar bar % set foo bar %
See also ?append