Richard Suchenwirth 2006-02-07 - For doing some OO sugar, I needed a way that interp aliases are cleaned up when the proc scope where they were defined is left. Here's my solution with a guard variable, to which an unset trace is tied:
proc alias {name = args} { upvar 1 __$name __$name eval [list interp alias {} $name {}] $args set __$name "" trace var __$name u "interp alias {} $name {} ;#" } proc test {} { alias up = string toupper return [up hello],[up world] } 146 % test HELLO,WORLD 277 % up this invalid command name "up"
NEM cautions though that the scope of aliases aren't really proc local, e.g.:
% proc test2 {} { alias up = string toupper return [test],[up more] } % test2 invalid command name "up"