Posted to tcl by colin at Wed Aug 04 05:54:28 GMT 2010view raw

  1. foreach x {get? set? unset? witharray equal apply capture nlappend in ni list diff switch transmute} {
  2. namespace ensemble configure dict -map [linsert [namespace ensemble configure dict -map] end $x ::tcl::dict::$x] -unknown {::apply {{dict cmd args} {
  3. if {[string first . $cmd] > -1} {
  4. if {[string index $cmd end] eq "?"} {
  5. ::set opt ?
  6. ::set cmd [string trim $cmd ?]
  7. } else {
  8. ::set opt ""
  9. }
  10. ::set cmd
  11. if {[llength $args]} {
  12. # [dict a.b.c] -> [dict get $a b c]
  13. return [::list dict set$opt {*}[::split $cmd .]]
  14. } else {
  15. # [dict a.b.c x] -> [dict set a b c x]
  16. ::set cmd [::lassign [::split $cmd .] var]
  17. ::upvar 1 $var v
  18. return [::list dict get$opt $v {*}$cmd]
  19. }
  20. }
  21. } ::tcl::dict}}
  22. }
  23. ::unset x
  24. }