Dear Maintainer, I'm try to learning tk and I think I have found a bug. I'm try to understand nested dict and I have done a very simple script:
Hi Davide,
As far as I can see, there's nothing wrong with Tcl here. You just
treat a list as a dict, hence the confusion. See this simpler example:
% set M {A B C D C {1 2}}
A B C D C {1 2}
Here, $M contains a list (actually, a string which can be interpreted
as a list). But we can try to interpret it as a dict:
% dict lappend M C 3
A B C {1 2 3}
Here, $M is reinterpreted as a dict, with odd items A, C, C as its
keys, and even items B, D, {1 2} as values. The problem is that there
is the duplicate key C, so Tcl had to drop one of its values (the last
one overwritten the first one upon creation of the dict). After that,
3 was appended to the list {1 2}.
Cheers!
Hi Sergei,
I'm very sorry for my mistakes :-(
Thanks for your explanation.
On nested dict there are very few documentation and, at first, I don't
have fully understand the examples on the man page. So I have search and
found a site that tell that the only way to modify a nested dict is with
"dict with"... and I have make some mistakes...
I have try to understand dict better and found that you can modify
nested dict also with "dict set"
I think now I have understand nested dict.
# create a nested dict
% set MyDict [dict create l0a 1 l0b1 1 l0c {l1a 2 l1b {l2a {l3a 4 l3b 4}
l2b 3} l1c 2 l1d 2} l0d 1 l0e 1]
l0a 1 l0b1 1 l0c {l1a 2 l1b {l2a {l3a 4 l3b 4} l2b 3} l1c 2 l1d 2} l0d 1
l0e 1
# you can add new values or update with dict set
% dict set MyDict l0c l1b l2d {l3A 4 l3B 4}
l0a 1 l0b1 1 l0c {l1a 2 l1b {l2a {l3a 4 l3b 4} l2b 3 l2d {l3A 4 l3B 4}}
l1c 2 l1d 2} l0d 1 l0e 1
# you can append new value with dict lappend and dict with
% dict with MyDict l0c l1b {dict lappend l2d l3C 4}
l3A 4 l3B 4 l3C 4
% echo $MyDict
l0a 1 l0b1 1 l0c {l1a 2 l1b {l2a {l3a 4 l3b 4} l2b 3 l2d {l3A 4 l3B 4
l3C 4}} l1c 2 l1d 2} l0d 1 l0e 1
You can close this bug report.
Ciao
Davide