Created
April 6, 2019 22:45
-
-
Save sagax/580d297d57f24cfb3859829279ba4233 to your computer and use it in GitHub Desktop.
dot notation in dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set some {a {x 1 y 2 z 3} b { x 4 y 5 z 6} c { a {x 7 y 8 z 9}}} | |
proc d {param} { | |
set varname [lindex [split $param .] 0] | |
set params [lrange [split $param .] 1 end] | |
upvar $varname object | |
return [dict get $object {*}[join $params { }]] | |
} | |
puts "default: [dict get $some a x]" | |
puts "as js: [d some.a.x]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment