Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: uninvited members of associative array
On 2022-12-17 13:07, Lawrence Velázquez wrote:
I'm not sure why you brought this up. Are you using "set +A"
somewhere?
No, but I'm still curious as to how my array got fouled. As just
discussed with Roman, I'd been using a global 'IN' and thus it will
contain whatever was in it at the next assignment, and it seemed to me
that a possibility was that the overwrite was not clean. Reading up on
it, there's that +A and -- tho I don't really understand --, it seemed
possible that it might force a complete overwrite. But I'm absolutely
happy with my local IN, that's got to be better anyway. And, per your
advice, I have 'typeset -p's locked and loaded all over the place.
Commented, but ready to spring into action at the next sign of trouble.
This is another lesson in how one can't take arrays for granted,
especially, it seems, AAs. BTW tx for example of what +A does, now I
understand. Easy if it's explained clearly.
Bart:
... assign to array" where "array" may
be either normal or associative. But if the array doesn't already
exist, it is implicitly created as a normal array. So you must
pre-declare names with "local -A" or similar if you want them treated
as associative.
Too bad it's not created as the same type as the input. Indeed, aren't
there cases where even declared types are changed? Like, don't scalars
convert to integers when you perform arithmetic on them? By the same
logic one might expect IN to become associative by virtue of the
assignment even if it was a plain vanilla '-a' previously.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author