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

Re: PATCH: typeset -P



On Sep 30,  8:46pm, Peter Stephenson wrote:
}
} The chunk in Src/subst.c is unrelated apart from being required by a
} test I've just added.  It ensures we don't elide empty nodes from the
} list when using key / value pairs.

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.

} 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.)

Aside -- *prior to* this patch:

torch% () { typeset -p 1 } foo
(anon):typeset: no such variable: 1
torch% () { typeset -p @ } foo
torch% () { typeset -p \* } foo
torch% () { typeset -p # } foo
torch% () { typeset -p ARGC } foo
torch% () { typeset -p argv } foo
typeset -g -a argv=( foo )

So individual positional parameters are "no such variable" which nicely
makes this new syntax usable, yet the argv variants are recognized but
not always printable.  (Also not clear that the -g is correct for argv,
but I think it's merely extraneous rather than wrong.)



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