Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: typeset -P
On Sat, 30 Sep 2017 17:11:54 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Hrm, this makes me notice that there's a useful case for typeset -p to
> output the [k]=v syntax even for traditional arrays. Consider:
>
> % typeset -a onek=([1024]=something)
> % typeset -p 1 onek
>
> We could skip the initial 1023 lines of '' if we used the new syntax.
> On the other hand, we'd waste a bunch of bytes on [N]=... if the array
> was *not* mostly empty, so most of the time the old syntax is likely
> more compact.
Unfortunately, unlike bash, arrays aren't sparse. So the intervening
elements that haven't been set are identical to any that have been set
explicitly to any empty string. Of course, that could be adopted as a
convention --- on re-input the effect is the same, which is ultimately
the key point.
> } One other minor compatibility note: the existing typeset -p
> } prints a space between the parentheses of an empty array. [...]
> } I've removed this space for typeset -p1.
>
> Interesting:
>
> torch% typeset -p x
> typeset -a x=( )
> torch% typeset -p 1 x
> typeset -a x=()
>
> (I don't really care either, but somebody is probably going to notice
> and file a bug report.)
I only changed it because I was asked.
Cosmetic differences between -p and -p1 are quite explicitly not a bug.
I'll commit it as it stands (with a correction from Daniel).
Hmm, maybe I'll make typeset -p0 the same as -p for consistency.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author