Posted to tcl by aspect at Mon Oct 20 05:52:02 GMT 2014view raw
- package require lambda
- proc dict-ref {dict args} {
- lambda {dict keys args} {
- switch [llength $args] {
- 0 {
- uplevel 1 "dict get \$$dict $keys"
- }
- 1 {
- tailcall dict set $dict {*}$keys $args
- }
- default {error "Expected 0 or 1 args"}
- }
- } $dict $args
- }
- proc foo {d1} {
- set x1 [dict-ref d1 a b]
- set x2 [dict-ref d1 x y]
- puts "x1 is [{*}$x1]"
- {*}$x1 555
- puts "x1 is [{*}$x1]"
- puts "x2 is [{*}$x2]"
- {*}$x2 999
- puts "x2 is [{*}$x2]"
- return $d1
- }
- set d {a {b 0 c 0} x {y 1 z 1}}
- set d [foo $d]
- puts $d