Richard Suchenwirth 2005-12-12 - In the Tcl chatroom, CMcC said:
You know, in retrospect, I think set x a b c should be equivalent to [set x [list a b c]
Well, Tcl is where wishes come true :) Here's my code that seems to work fine, as far as I've tested. I had to reuse the _var name for upvar, so the error message comes right if the variable doesn't exist yet:
rename set _set proc set {_var args} { upvar 1 $_var $_var _set ll [llength [info level 0]] if {$ll==3} { _set $_var [lindex $args 0] } elseif {$ll>3} {_set $_var $args} _set $_var }
Testing:
% source myset.tcl % set foo can't read "foo": no such variable % set foo 1 1 % set foo 1 % set bar 2 3 4 2 3 4 % set bar 2 3 4 % set grill {{}} {} % set grill {}
So far it looks as expected. But bytecode compilation may lose performance if a fundamental like set is pulled from under its feet...