Version 0 of proc-local alias

Updated 2006-02-07 18:49:05 by suchenwi

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"

Category Development