Skip to content

Instantly share code, notes, and snippets.

@sagax
Created April 6, 2019 22:45
Show Gist options
  • Save sagax/580d297d57f24cfb3859829279ba4233 to your computer and use it in GitHub Desktop.
Save sagax/580d297d57f24cfb3859829279ba4233 to your computer and use it in GitHub Desktop.
dot notation in dict
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