Posted to tcl by aspect at Thu Jul 10 14:45:31 GMT 2014view raw
- proc withArray {name args} {
- upvar 1 $name a
- set script [lmap name [array names a] {
- list upvar 1 a($name) $name
- }]
- set script [join $script \n]
- append script \n[concat {*}$args] ;# mostly I do this out of superstition
- apply [list {} $script]
- }
- proc test {} {
- set a(bar) 3
- set a(baz) 10
- withArray a {
- set foo [expr {$bar+$baz}]
- incr baz
- }
- parray a
- }
- test
- #a(bar) = 3
- #a(baz) = 11
- #a(foo) = 13