Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Empty element elision and associative arrays (was Re: Slurping a file)



On Mon, Jan 15, 2024 at 2:02 AM Lawrence Velázquez <larryv@xxxxxxx> wrote:
There is no "inevitable" teration order; one must be usually be chosen and implemented
explicitly, which is extra complexity that many languages choose not to bother with.

Indeed. To be clear, several do choose to bother; examples include Python since 3.6, Ruby since 1.9, and PHP, which all maintain their associative data types in insertion order. (That introduces potential pitfalls in PHP, where all arrays are associative; regular ones just have numeric keys, but those can still be rearranged out of numerical order! _javascript_ avoids that pitfall by using numeric order for numeric keys while maintaining insertion order for non-numeric ones.)

Closer to home, the KornShell keeps its associative arrays in lexical order by key. Which is to say there is precedent for keeping things in a specified order, but Zsh doesn't do so. Even if it were changed such that it started to do so as of 6.0 or whatever, you'd still have to write code to check the version and either fail ungracefully or fall back to maintaining the order in a separate array anyway. So even in that world, it's simpler to just do the separate ordering in the first place, yielding code that works in any version – at least, any version with associative arrays.

--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author