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 2024-01-18 14:34, Bart Schaefer wrote:
  asc=( [one]=1 [two]=2 [nil]= )

The "not clever" pairwise assignment 
I don't want to sound to flippant.  Anything other than pairwise would obviously be much more difficult to implement and I myself have never seen any reason why simply maintaining the pairs should be considered a problem.  I did experience some crash and burns on first playing with A arrays, but it's not hard once you know how.
Associative arrays are maintained as hash tables for fast access.
It's something way over my head. 
... storing extra data about the order
(such as a linked list through the hash elements).  Zsh opted to do
neither of these on the premise that access to individual elements by
key is far more frequent than access to the entire table.

Sure.  Perhaps Mark has some idea of the nuts and bolts of the thing in ksh -- whether or not it's a labor to implement the determined order or not -- but that's up to you devs.  As it is, for diagnostics I do end up printing entire arrays, and it would be nice to have a predicted order but not if it's going to be any trouble.  Funny, now that I try to break the order I can't:

typeset -A asc=()
asc=( [one]=1 [two]=2 [three]=3 [four]=4 [five]=5 )
print -l "$asc"
asc[six]=6
print -l "$asc"
asc[two]=22
print -l "$asc"
asc[three]=
print -l "$asc"
asc[three]=33
print -l "$asc"
asc[one]=
print -l "$asc"
asc[one]=11
print -l "$asc"

1 5 4 2 3
1 5 4 2 3 6
1 5 4 22 3 6
1 5 4 22  6
1 5 4 22 33 6
 5 4 22 33 6
11 5 4 22 33 6

... once it decides on 'one five four two three' ... it keeps it.  How hard would it be to get the first hash 'right'?








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