if [llength [info commands p7proc]] { set Compiling true } else { set Compiling false source testing.tcl } if $Compiling { # # This kind of hack is no longer needed, since p7 now has a real (dict) type. # # However this does demonstrate using Global Tcl Variables from p7, # using ::set and ::unset etc. # p7class Dict {} p7proc (Dict)dCreate {} { set (Dict)self [new (Dict)] ::set "::_dicthack_$self\(0)" 0 ::unset "::_dicthack_$self\(0)" return $self } # If you dont dDestory, you have memory leaks in global var space. p7proc (void)dDestroy { (Dict)self } { ::unset "::_dicthack_$self" } p7proc dGet { (Dict)self (tcl)key } { ::set "::_dicthack_$self\($key)" } p7proc (void)dSet { (Dict)self (tcl)key (tcl)value } { ::set "::_dicthack_$self\($key)" $value } p7proc dKeys { (Dict)self } { ::array names "::_dicthack_$self" } } else { set d [dCreate] dSet $d number 111 dSet $d color blue dSet $d size XL AssertEq 111 {dGet $d number} AssertEq blue {dGet $d color} AssertEq XL {dGet $d size} AssertEq "color number size" {lsort [dKeys $d]} # watch the dDestory work, to eliminate memory leaks when done with the Dict AssertEq 1 {llength [info global _dicthack_*]} dDestroy $d AssertEq 0 {llength [info global _dicthack_*]} Okay }