From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Peter Stephenson <p.w.stephenson@ntlworld.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: PATCH: [key]=value syntax, work in progress
Date: Wed, 13 Sep 2017 11:14:04 +0200 [thread overview]
Message-ID: <30374.1505294044@thecus.kiddle.eu> (raw)
In-Reply-To: <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
.
next prev parent reply other threads:[~2017-09-13 11:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-11 20:51 Peter Stephenson
2017-09-11 20:56 ` Peter Stephenson
2017-09-12 20:25 ` Peter Stephenson
2017-09-12 20:28 ` Peter Stephenson
2017-09-13 7:13 ` Bart Schaefer
2017-09-13 8:53 ` Peter Stephenson
2017-09-13 16:44 ` Bart Schaefer
2017-09-14 20:48 ` Peter Stephenson
2017-09-19 1:13 ` Bart Schaefer
2017-09-13 9:14 ` Oliver Kiddle [this message]
2017-09-13 19:41 ` Peter Stephenson
2017-09-14 7:03 ` Daniel Shahaf
2017-09-14 20:38 ` Peter Stephenson
2017-09-16 10:30 ` Daniel Shahaf
2017-09-14 6:54 ` 'typeset -p' of assocs (was: Re: PATCH: [key]=value syntax, work in progress) Daniel Shahaf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=30374.1505294044@thecus.kiddle.eu \
--to=okiddle@yahoo.co.uk \
--cc=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).