-
-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maybe sort the output of the keys
command
#1025
Comments
But of course you knew that already. I agree that having them sorted is nice to have, as this has been an irritant to me too. But unless this is literally a two line fix (it might be), I wouldn't give this a really high priority at present. For my own uses, I'll just turn the above into a function, possibly without the trailing |
I don't know any languages that offer any promises in the order of keys in a hash/dictionary. I agree this would be nice in an interactive context, but then it should be a feature of the editor. Particularly since sorting the output of the |
That is true for hash based maps which is, as you note @zzamboni, a widely used implementation strategy. But there are tree based implementations that do guarantee the order of the keys. And some languages, such as Python, have had ordered dictionaries for a long time. Although, in the case of Python it wasn't the default behavior until very recently.
Me too. I'm not proposing restricting keys to strings. I'm proposing requiring that the keys for a particular map be the same data type; whether that is string, float64, list, or something else. Regardless of the merits of having
Since the keys are numbers I would expect the order to be 3, 11. Lists as keys also produce the wrong sorted order when coerced to strings:
|
There was an IM/Gitter discussion about this wherein @xiaq pointed out that preserving insertion order is often more useful than sorting the map's keys. Which is why Python's |
It would be okay if the output of |
Regarding whether map keys should be homogenous this, from "When to release Elvish 1.0", seems relevant:
|
Revisiting this I'm going to close this issue. It's now easy enough to do
I'm still convinced that heterogenous key types should be disallowed. Note that I am not arguing for disallowing heterogenous value types. |
Note that the
It's not obvious why maps should not include a similar restriction. Certainly the Go language, and pretty much all other languages, require maps to have a homogenous key type. |
Closing again, because even though Elvish maps allow heterogenous key types that will rarely be true in practice. And if someone wants to use heterogenous key types they should be aware that |
It would be nice if the output of
keys
was in a predictable order; i.e., sorted. Especially in an interactive context the current random order is somewhat annoying:The text was updated successfully, but these errors were encountered: