Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Typeset with array
On Tue, Jun 23, 2015 at 10:17 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Jun 23, 7:52pm, Mikael Magnusson wrote:
> }
> } This isn't really related to this series, but I noticed it now for the
> } first time; what's the deal with the space at the end of associative
> } arrays in typeset -p output?
>
> With a normal array, the number of elements is known, so you know when
> you've reached the last one and can skip printing the space after it.
>
> When traversing a hash table, you don't know if you've reached the last
> element until you've passed it; it's more straighforward to print out
> ("%s %s ", key, value) for every element than to keep track of whether
> you are past the first element but not yet at the last one.
Ah, that makes sense.
> If I were going to "fix" it for no reason other than the consistency,
> I'd simply add MORE spaces rather than try to squash that one.
>
> typeset -a a
> a=( b )
> typeset -A b
> b=( b c )
This would also be consistent with xtrace output, so I agree :).
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author