From: Ian on
Hi,

Unexpected behaviour (for me at least!):

% set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
1 c 2 a
% set tcl_patchLevel
8.5.8


"Looking at" a list as a dict seems to be modifying the list...

Is this a bug?

cheers,
Ian
From: ZB on
Dnia 19.05.2010 Ian <i.d.braithwaite(a)gmail.com> napisa�/a:

> % set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
> 1 c 2 a
> % set tcl_patchLevel
> 8.5.8
>
>
> "Looking at" a list as a dict seems to be modifying the list...

And do you know, what is most interesting? That it depends on the notation:

#v+
% set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
1 c 2 a
% set b [list 1 b 1 c 2 a]
1 b 1 c 2 a
% dict exists $b 1
1
% set b
1 b 1 c 2 a
% set c [list 1 b 1 c 2 a]; dict exists $c 1
1
% set c
1 c 2 a
% set d [list 1 b 1 c 2 a]
1 b 1 c 2 a
% dict exists $b 1; set d
1 b 1 c 2 a
%
#v-

As you can see, the problem occurs only in case, when assigning a list and
checking the existence of dictionary are in one line.

Tested in 8.6.b1.
--
Zbigniew
From: MartinLemburg on
This behavior is completely ok!

A dict(ionary) can contain only one value per key, so if a list is
treated as dict(ionary) containing more than one value per key, the
last key/value pair is used.

Thus ...

set list {a 1 a 2 b 3 b 4}

.... used as dict(ionary) ...

set dict [dict create {*}$list]

.... will create not the same data:

% set list
a 1 a 2 b 3 b 4
% set dict
a 2 b 4

As long no multi-key dictionary will be introduced, this behavior is
completely wanted and correct!

Best regards,

Martin Lemburg

On 19 Mai, 11:47, ZB <zbTHIS...(a)ispid.THIS-NOcom.pl> wrote:
> Dnia 19.05.2010 Ian <i.d.braithwa...(a)gmail.com> napisa³/a:
>
> >   % set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
> >   1 c 2 a
> >   % set tcl_patchLevel
> >   8.5.8
>
> > "Looking at" a list as a dict seems to be modifying the list...
>
> And do you know, what is most interesting? That it depends on the notation:
>
> #v+
>   % set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
>   1 c 2 a
>   % set b [list 1 b 1 c 2 a]
>   1 b 1 c 2 a
>   % dict exists $b 1
>   1
>   % set b
>   1 b 1 c 2 a
>   % set c [list 1 b 1 c 2 a]; dict exists $c 1
>   1
>   % set c
>   1 c 2 a
>   % set d [list 1 b 1 c 2 a]
>   1 b 1 c 2 a
>   % dict exists $b 1; set d
>   1 b 1 c 2 a
>   %
> #v-
>
> As you can see, the problem occurs only in case, when assigning a list and
> checking the existence of dictionary are in one line.
>
> Tested in 8.6.b1.
> --
> Zbigniew

From: miguel sofer on
Verified, opened bug #110894:
https://sourceforge.net/tracker/?group_id=10894&atid=110894

Thx
Miguel

ZB wrote:
> Dnia 19.05.2010 Ian <i.d.braithwaite(a)gmail.com> napisa�/a:
>
>> % set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
>> 1 c 2 a
>> % set tcl_patchLevel
>> 8.5.8
>>
>>
>> "Looking at" a list as a dict seems to be modifying the list...
>
> And do you know, what is most interesting? That it depends on the notation:
>
> #v+
> % set a [list 1 b 1 c 2 a]; dict exists $a 1; set a
> 1 c 2 a
> % set b [list 1 b 1 c 2 a]
> 1 b 1 c 2 a
> % dict exists $b 1
> 1
> % set b
> 1 b 1 c 2 a
> % set c [list 1 b 1 c 2 a]; dict exists $c 1
> 1
> % set c
> 1 c 2 a
> % set d [list 1 b 1 c 2 a]
> 1 b 1 c 2 a
> % dict exists $b 1; set d
> 1 b 1 c 2 a
> %
> #v-
>
> As you can see, the problem occurs only in case, when assigning a list and
> checking the existence of dictionary are in one line.
>
> Tested in 8.6.b1.

From: ZB on
Dnia 19.05.2010 MartinLemburg(a)Siemens-PLM <martin.lemburg.siemens-plm(a)gmx.net> napisa�/a:
> This behavior is completely ok!
>
> A dict(ionary) can contain only one value per key, so if a list is
> treated as dict(ionary) containing more than one value per key, the
> last key/value pair is used.

I think you completely missed two points:

1. That "dict exist" seems to be something, that has influence on data -
while, actually, it should have only been an "examining tool", and nothing
more.

2. That it depends on the way, you write it: all in one line, or split into
three verses.

Or is it me, who's missing something?

From the manual:

#v+
dict exists dictionaryValue key ?key ...?

This returns a boolean value indicating whether the given key (or path of
keys through a set of nested dictionaries) exists in the given dictionary
value. This returns a true value exactly when dict get on that path will
succeed.
#v-

There's nothing about changing the list's/dict's contents - be it properly,
or improperly built. Yes: a dictionary should have unique keys - but still
there's a question, why it has been "fixed" by "dict exists" (and why only
in the case, when it was in the same line, as initial "set [list ...]").
--
Zbigniew