|
2013-01-08
| ||
| 20:46 | • Closed ticket [3599906fff]: dict command has side effects on foreach artifact: 34497077e9 user: dkf | |
| 20:46 | • Ticket [3599906fff]: 4 changes artifact: 97694a0276 user: dkf | |
| 20:36 | • Open ticket [3599906fff]. artifact: 28ada1b3ab user: heinrichmartin | |
| 18:09 | • Pending ticket [3599906fff]. artifact: 0f11837d41 user: dkf | |
| 08:52 | • New ticket [3599906fff]. artifact: 25a7dc9f24 user: heinrichmartin | |
dict command has side effects on foreach
Closed / Duplicate3599906fffffffffffffffffffffffffffffffffCreated 14 years agoUpdated 14 years ago
Descriptionplain2013-01-08 08:52:22
"dict keys" takes a dictionaryVALUE, but affects the variable's interpretation by foreach:
expect:/tmp$ set tcl_version
8.5
expect:/tmp$ set x {1 a 2 b 3 c 3 d 3 e} ;# store a list which also is a dictionary value
1 a 2 b 3 c 3 d 3 e
expect:/tmp$ foreach {key val} $x {puts "$key -> $val"} ;# print pairs of list elements correctly
1 -> a
2 -> b
3 -> c
3 -> d
3 -> e
expect:/tmp$ dict keys $x ;# the argument is passed by value, isn't it? (see dict or the dodekalogue)
1 2 3
expect:/tmp$ foreach {key val} $x {puts "$key -> $val"} ;# we had that very command, and x was not altered.
1 -> a
2 -> b
3 -> e
expect:/tmp$ set x ;# indeed, x was not altered
1 a 2 b 3 c 3 d 3 e
Obviously, variables are stored in best-guess-data-structures (lists, dictionaries, ...) whenever a corresponding command is used.
This performance benefit must not affect consistency.
Why does foreach treat dict-variables differently?
This should not happen, we do have "dict for"!
dkfplain2013-01-08 18:09:29
This looks like a dupe of 3004007 and that was fixed a few years ago (in time for 8.5.9). What does [info patchlevel] report for a buggy run? I can't duplicate using your exact code with the tip of the 8.5 branch...
heinrichmartinplain2013-01-08 20:36:11
My bad, I did not consider the bugfix version. We are running Debian Squeeze stable and it looks like it's finally time for backports. I leave it to you to close the ticket. Thanks for the help, I did not find the duplicate as it does not contain "foreach". Sorry!
dkfplain2013-01-08 20:46:49
This artifact has been marked as a duplicate of artifact 3004007 with reason: older version under test than expected
dkf Closed ticket [3599906fff].
[History diff]2013-01-08 20:46:50
Log in (anonymous is fine) to add a comment.