if [llength [info commands p7proc]] { set Compiling true } else { set Compiling false source testing.tcl } if $Compiling { # for using raw dict from Tcl p7proc (dict)dnew {} { new (dict) } p7proc dget { (dict)d (tcl)key } { k $d($key) } p7proc (dict)dset { (dict)d (tcl)key (tcl)value } { set d($key) $value set d } p7proc dnames { (dict)d } { names $d } p7proc (dict)dunset { (dict)d (tcl)k } { unset d($k) set d } p7proc (dict)transfer { (dict)d } { set (tcl)z $d set (dict) $z } p7proc (tcl)concepts {} { new (dict)spanish set spanish( "one" ) uno set spanish( "two" ) dos new (dict)french set french( "one" ) un set french( "two" ) deux new (dict*)z 3 set z(0) $spanish set z(2) $french set z } } else { set d [dnew] AssertEq "" {set d} set d [dset $d number 111] set d [dset $d color blue] set d [dset $d size XL] AssertEq 111 {dget $d number} AssertEq blue {dget $d color} AssertEq XL {dget $d size} # implementation flaw: just reading mumble creates the name AssertEq "" {dget $d mumble} AssertEq "color number size" {lsort [dnames $d]} AssertEq "color number size" {lsort [dnames [transfer $d]]} set d [dunset $d {mumble}] AssertEq "color number size" {lsort [dnames [transfer $d]]} AssertEq blue {dget $d color} set d [dunset $d "color"] AssertEq "number size" {lsort [dnames [transfer $d]]} AssertEq "" {dget $d color} puts [concepts] } if $Compiling { # these encapusulate the (dict) in a class Dict. They use BIG letter D. p7class Dict { (dict)d } p7proc (Dict)Dnew {} { new (Dict)z set z(d) [new (dict)] set z } p7proc Dget { (Dict)this (tcl)key } { k $d($key) } p7proc (void)Dset { (Dict)this (tcl)key (tcl)value } { set d($key) $value } p7proc Dnames { (Dict)this } { names $d } p7proc (void)Dunset { (Dict)this (tcl)key } { set (dict)tmp $d unset tmp($key) } } else { set d [Dnew] 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} # implementation flaw: just reading mumble creates the name AssertEq "" {Dget $d mumble} AssertEq "color mumble number size" {lsort [Dnames $d]} Dunset $d mumble AssertEq "color number size" {lsort [Dnames $d]} Okay }