Posted to tcl by sebres at Fri Sep 21 17:12:49 GMT 2018view raw
- In my opinion, the certain "immutability" of dict + EIAS (as well as the absence of weak/smart pointers) avoid the normal usage of the dict as real branch-tree (at least updatable one, e. g. if navigating over tree branches, etc)...
- I have own native tcl-object-types in TclSE (struct, record, etc), that are dict-similar, where one can do things like:
- % set t [new record from json {"a":{"aa":1,"ab":2},"b":{"ba":3,"bb":4},"c":{"ca":5,"cb":6}}]
- % $t as string
- a {aa 1 ab 2} b {ba 3 bb 4} c {ca 5 cb 6}
- % $t as json -pretty
- {
- "a" : {
- "aa" : 1,
- "ab" : 2
- },
- "b" : {
- "ba" : 3,
- "bb" : 4
- },
- "c" : {
- "ca" : 5,
- "cb" : 6
- }
- }
- % set b [$t . b]
- % $b set bc 5
- % $t as string
- a {aa 1 ab 2} b {ba 3 bb 4 bc 5} c {ca 5 cb 6}
- % $b clear
- % $t as string
- a {aa 1 ab 2} b {} c {ca 5 cb 6}
- % $b set x x
- % proc some-proc {branch args} { $branch update $args }
- % some-proc $b y Y z Z
- % $t as string
- a {aa 1 ab 2} b {x x y Y z Z} c {ca 5 cb 6}
- % $t . b unset z
- % $b as string
- y Y
- % $b record z { bza 8 bzb 9 }
- % $b . z set "a&c" [list [$t . a] [$t . c]]
- % [lindex [$b . z . "a&c"] 0] set ac 3
- % [lindex [$b . z . "a&c"] 1] set cc 7
- % $t as json -pretty
- {
- "a" : {
- "aa" : 1,
- "ab" : 2,
- "ac" : 3
- },
- "b" : {
- "x" : "x",
- "y" : "Y",
- "z" : {
- "bza" : 8,
- "bzb" : 9,
- "a&c" : [
- {
- "aa" : 1,
- "ab" : 2,
- "ac" : 3
- },
- {
- "ca" : 5,
- "cb" : 6,
- "cc" : 7
- }
- ]
- }
- },
- "c" : {
- "ca" : 5,
- "cb" : 6,
- "cc" : 7
- }
- }
- Simply try to do the same using tcl dict's.