I need to compare 2 dicts disregarding order of keys (just equal/not equal), preferably without unnecessary generation of string representations. Can't believe it's not in the core :(
I'd prefer to import it from Tcllib or other standard package rather than copy-paste from the Wiki
thanks in advance!
I need to compare 2 dicts disregarding order of keys (just equal/not equal), preferably without unnecessary generation of string representations. Can't believe it's not in the core :(
I'd prefer to import it from Tcllib or other standard package rather than copy-paste from the Wiki
thanks in advance!
**************************
I need to compare 2 dicts disregarding order of keys (just equal/not
equal), preferably without unnecessary generation of string
representations. Can't believe it's not in the core :( I'd prefer to
import it from Tcllib or other standard package rather than copy-paste
from the Wiki thanks in advance!
When I left the scene, dict was a pretty new addition and I never got
around to learning it. I just read the man page and found it very
confusing. I don't see how it's much different from a list. Looks like
it's a list-like array or an array-like list. Whatever. I need to put
some time aside to study it carefully.
With that said, in my ignorance, I suppose you can traverse the entire content of a dict, can't you? It would seem useless to me if you can't.
So it must be possible and not even very difficult to write a proc
that will "gut" or "disassemble" a dict in multiple parts that can then
be compared directly with the counterparts of another dict, one to one.
A little bit like comparing two directories, each one with multiple subdirectories and files.
Thank you all for responses. Now I understand why there's no generic
[dict equal]
yet another thing to reinvent in my code :-( alongside assert, sleep,
vwait with timeout and endless argument parsing
I need to compare 2 dicts disregarding order of keys (just equal/not equal), preferably without unnecessary generation of string representations. Can't believe it's not in the core :(
I'd prefer to import it from Tcllib or other standard package rather than copy-paste from the Wiki
thanks in advance!
For example:
% set a [dict create val1 [list val11 val12]]
val1 {val11 val12}
% set b [dict create val1 [dict create val11 val12]]
val1 {val11 val12}
% set c [dict create val1 "val12 val12"]
val1 {val11 val12}
'a' has a *list* as value for the key, 'b' has a *dict* as value for the
same key, 'c' a *string*. They all have the same string representation,
but are they *equal*?
For files and directories you have [file isdirectory] and [file isfile],
but that info is not easily available for the dict elements (and
probably not even reliably, considering "dict set a val1 val11 val13" is possible).
R'
* Luc <no@no.no>
| About the dicts, I don't know. I still don't know how they really work
| until I reserve some time to study them adequately.
Always a good idea :-) I don't know the internals of dicts either, but
Rich has listed the advantages when using them instead of arrays up-thread.
| I'm just very stubborn. It can be a valuable trait in certain situations.
I wouldn't call that stubborn in this context. If you're honestly
trying to understand what this is all about, that's a Good Thing¹ IMHO.
R'
---
¹ http://www.catb.org/~esr/jargon/html/G/Good-Thing.html
On Thu, 10 Nov 2022 11:58:54 +0100, Ralf Fassel wrote:
For example:
% set a [dict create val1 [list val11 val12]]
val1 {val11 val12}
% set b [dict create val1 [dict create val11 val12]]
val1 {val11 val12}
% set c [dict create val1 "val12 val12"]
val1 {val11 val12}
'a' has a *list* as value for the key, 'b' has a *dict* as value for the
same key, 'c' a *string*. They all have the same string representation,
but are they *equal*?
For files and directories you have [file isdirectory] and [file isfile],
but that info is not easily available for the dict elements (and
probably not even reliably, considering "dict set a val1 val11 val13" is
possible).
R'
For the strict sake of comparison, I would treat all occurrences of
[llength $list] <= 1 as strings.
Or maybe treat all non-space strings as [list $string].
About the dicts, I don't know. I still don't know how they really work
until I reserve some time to study them adequately.
Am 10.11.2022 um 17:39 schrieb Ralf Fassel:
* Luc <no@no.no>
| About the dicts, I don't know. I still don't know how they really
work | until I reserve some time to study them adequately.
Always a good idea :-) I don't know the internals of dicts either,
but Rich has listed the advantages when using them instead of arrays
up-thread.
| I'm just very stubborn. It can be a valuable trait in certain
situations.
I wouldn't call that stubborn in this context. If you're honestly
trying to understand what this is all about, that's a Good Thing
IMHO.
R'
---
http://www.catb.org/~esr/jargon/html/G/Good-Thing.html
To guess the type of a list value, you may look what the pdict does
with values:
https://wiki.tcl-lang.org/page/pdict%3A+Pretty+print+a+dict?R=0&O=pdict&W=
Look at the line:
[string match "value is a dict*"\
[tcl::unsupported::representation $val]]
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 493 |
Nodes: | 16 (2 / 14) |
Uptime: | 183:42:45 |
Calls: | 9,705 |
Files: | 13,737 |
Messages: | 6,179,548 |