Posted to tcl by aspect at Mon Oct 20 05:52:02 GMT 2014view raw

  1. package require lambda
  2. proc dict-ref {dict args} {
  3. lambda {dict keys args} {
  4. switch [llength $args] {
  5. 0 {
  6. uplevel 1 "dict get \$$dict $keys"
  7. }
  8. 1 {
  9. tailcall dict set $dict {*}$keys $args
  10. }
  11. default {error "Expected 0 or 1 args"}
  12. }
  13. } $dict $args
  14. }
  15.  
  16.  
  17. proc foo {d1} {
  18. set x1 [dict-ref d1 a b]
  19. set x2 [dict-ref d1 x y]
  20. puts "x1 is [{*}$x1]"
  21. {*}$x1 555
  22. puts "x1 is [{*}$x1]"
  23. puts "x2 is [{*}$x2]"
  24. {*}$x2 999
  25. puts "x2 is [{*}$x2]"
  26. return $d1
  27. }
  28.  
  29. set d {a {b 0 c 0} x {y 1 z 1}}
  30. set d [foo $d]
  31. puts $d
  32.