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

Re: PATCH: [key]=value syntax, work in progress



On Wed, Sep 13, 2017 at 1:53 AM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 13 Sep 2017 00:13:35 -0700
> Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>
>> typeset -A x=([y]=2 [z]=1)
>>
>> and that's the only way to assign an associative array; if you assign without
>> the [k]=v syntax the parameter converts into an ordinary array.  Is this going
>> to get enforced when KSH_ARRAYS and/or KSH_TYPESET are in effect?
>
> That's probably a good idea.

I would anticipate a number of problems with the function libraries
for cases where "emulate zsh" is not declared.

> By the way, the mixed syntax is going to be a nightmare:
>
> $ array=(* [100]=foo)
>
> is entirely valid, which means much more work

There's an easy way out of this:  If the first element in the parens
does not use the [key]= syntax then none of them do.  That's the only
way to make the mixed syntax relatively backward-compatible with
globbing in any case.  (How DO you assign "all file names containing
an equal sign following a leading digit" to an array in bash/ksh,
anyway?)

> typeset -A hash
> hash=(key1 [key2]=value)

Either "[key2]=value" is a value, or this converts hash from an
associative array to a plain one.  The more interesting case is

typeset -A hash=(key1 [key2]=value)

where the choices are that either "[key2]=value" is a value, or the
whole thing is a syntax error (see KSH_TYPESET remarks above).

In both variations if  "is a value" is chosen then it has to be
globbed, which will probably result in a file not found.

Then we have all the worms in Oliver's can.



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