Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: [key]=value syntax, work in progress
- X-seq: zsh-workers 41696
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Subject: Re: PATCH: [key]=value syntax, work in progress
- Date: Wed, 13 Sep 2017 11:14:04 +0200
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1505303155; bh=i3Ph4GlFnRMeJ8lP6A7/IBI4P6QKRYzgc63Y8PwfZTU=; h=From:References:To:Subject:Date:From:Subject; b=U+5MNG/aVpN8sFYPGpCCm11q+tMiYaQ3KfEOJGi0E0I9cw2eG8tjgBjdhPTrq7nh2qWv89wg2z3oEDqTiM9M70HRLF9NnGACEqG/DdtVIk9+t79Cqpc4RNGHn15RGvI8UVs3/Gu8/a5ImLRDxD1bsUqyimZyum65oZ8awYSGYhF78rm1ZH4zINTM2/ZKeyRN3waaygWDJ6PLmjegLKjtNEysWg1+wY1dt9cYBUZ+SLn5E2S64Vi3mjcr0TxG2HGrj9KmlP3NZQrIBWxlMSTF6ActtkFQeWhWEE87Jusuq5MDoZpJLwubw8cCXxfMuuJMH2s/IDimFcN8oXx7PATt3Q==
- In-reply-to: <20170912212519.3d873212@ntlworld.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <20170911215115.6aa27dec@ntlworld.com> <20170912212519.3d873212@ntlworld.com>
Peter wrote:
> (I take silence to mean "grmf why are you even bothering to do this
Not at all. Is definitely an enrichment to zsh.
> +elements must match this form or an error is genereted; likewise, if the
Note typo.
Appending has issues - seg fault with:
arr=( 1 2 3 )
arr+=( [5]=val )
Bash actually appends element wise with +=. Ksh doesn't. Ksh instead would
require an inner +=. Ksh behaviour on this seems far more logical to me.
ksh$ arr+=( [0]+=X )
bash$ arr+=( [0]=X )
A range doesn't evoke an error, (or clever multi-element assignment):
% arr=( [1,2]=x )
% typeset -p arr
typeset -a arr=( x )
Note that is the first element so it must be parsing the range rather than
treating the , as the arithmentic , operator (and returning 2).
What about brace expansion:
% arr=( [{2..3}]=x )
zsh: bad math expression: operand expected at `{2..3}'
bash$ arr=( [{2..3}]=x )
bash$ typeset -p arr
declare -a arr='([0]="[2]=x" [1]="[3]=x")'
ksh prints a syntax error.
% arr=( [2]={a,b,c} )
% typeset -p arr
typeset -a arr=( '' '{a,b,c}' )
Thats the same in ksh.
Bash appears to disable the []= form as soon as it sees brace expansion.
Ksh/current zsh patch behaviour seems preferable to me.
This is interesting (syntax error in bash). Could be good to reserve this
syntax for ksh style nested assignments.
% arr=( [1]=(x y z) )
% typeset -p arr
typeset -a arr=( '(x y z)' )
Any user deserves what they get with this but note that as a fatal error, the
shell bails out completely. Might be nice if this could be non-fatal with the
effect that the array is not assigned.
% arr=( [99999999999]=hello )
zsh: fatal error: out of memory
It would be good to make typeset -p output use this new syntax by default
for associative arrays because (without other cues like alignment) it
can be clearer which items in the list are keys and which values. Are
there certain keys that can't easily be quoted with the new syntax? If
so, typeset -p could mix the two formats once that's supported.
I checked subscript flags (along with @ and *) and it is correctly not parsing
them as subscript flags so we just get bad math expression errors - which is
good. Completion does try to complete them though. Otherwise, completion needs
adapting to work for associative array assignments. It appears to already just
work for arrays apart from relying on setopt magicequalsubst to be useful after
the equals sign.
> OK, so bash says this is valid:
> $ array=([3]=three four [1]=one two)
Note also:
$ array=([3]=three four [1]=one two overwrite)
Oliver
.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author