Version 2 of Shadow Variables

Updated 2004-08-12 12:41:52 by RHS

RHS 12August2004

A package for treating parts of one variable as a whole other variable. More description to come later, but the basic idea (via some of the tests) is:

 test list.stackLevels-1.1 {
    Passing the name of a child into a proc to be upvar'd\
        will still modify the parent
 } -setup {
    reset main child
 } -body {
    proc modify {&var} {
        upvar 1 ${&var} var
        set var [string toupper $var]
    }
    set main {a b {c d} e}
    shadow child main 2
    modify child
    set main
 } -result {a b {C D} e}

 test array.stackLevels-1.1 {
    Pass the child into a proc, and change it via upvar
 } -setup {
    reset main child
 } -body {
    proc modify {&var} {
        upvar 1 ${&var} var
        foreach {key value} [array get var] {
            set var($key) [expr {$value * 20}]
        }
    }
    array set main {a 1 b 2 c 3}
    shadow child main
    modify child
    getArraySorted main
 } -result {a 20 b 40 c 60}

 test array.element-1.1 {
    Shadow an array element, parent follows the 'array get'\
        value of the child
 } -setup {
    reset main child
 } -body {
    array set main {a {A 1} b {B 2}}
    shadow child main b
    set child(B) [expr {$child(B) * 2}]
    getArraySorted main
 } -result {a {A 1} b {B 4}}

Feel free to take a look at the code for it at http://robert.rkseeger.net/shadow.tar.gz for now. I'll write up more information on what I was trying to do, and the limits of that approach, some other time.