Piotrek wrote:
bearophile Wrote:
I'd really like the "default" iteration on an AA to yield its keys, instead of
values as currently done. Because if I have a key I can find its value, while the
opposite is not possible, so having keys is much more useful. This is true in Python too.
In my dlibs all iterables and functions behave like this. The current D design is just a
design mistake ad Walter was wrong on this.
No! No! No! Maybe you are wrong. Or it's a metter of taste. I remember that I
spent many hours on finding bug in python's script written by me in my job. The
reason was the python's behaviour decribed by you. Then I couldn't understand
why the hell iterating on collection returns a key in the first place. It's so
not intuitive. Your explanation is not even close in convincing me. If I wanted
keys I would write:
foreach (key, value; set) or (key; set.keys)
Why not mandate using both keys and values? That should eliminate ambiguity.
Essentially, an associative array would be a Tuple!(Tkey, Tvalue)[] with
some extra accessors.