From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27412 invoked by alias); 13 Sep 2017 11:46:03 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 41696 Received: (qmail 3312 invoked by uid 1010); 13 Sep 2017 11:46:03 -0000 X-Qmail-Scanner-Diagnostics: from sonic307-54.consmr.mail.ir2.yahoo.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(87.248.110.31):SA:0(-4.7/5.0):. Processed in 3.073007 secs); 13 Sep 2017 11:46:03 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: okiddle@yahoo.co.uk X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-YMail-OSG: HXWoyZwVM1lMr31sNwbZhXpZ7tivdiF.vFwT8c1nqJeV1opgOra15RlhD6QGPcK mIlZXEPVNW_OxfQAPlmeQAYlQ0H7yhaiaQeE6onYf9VktkzAx5br5x_z19BArcX73Skk28p57FRX 6LNYFqoO.b.eEysXkvzOsvVtnW1kalowzuX8JHxhZFL1fFKtK2p2iuFfZYEc6TUSesX2zdZXpLqF 7fN.cBNal7LGylpcmB_kp1qD7aHrQZiYNoyEtJEXYz6trcAi5_QdW7JWIrROQa1OCANr05QGc6tY Dd2GcLUx6ScljeZj.vwA7YUjzqYs9chPnPfCgdUJqH.p_9ZwQa0RufvRgV7u.q1EOv_iEKN5vV3N R29kLeJO8EpQd_OQ2fxW4X3FqDrQLxF7LuH6hiQBrpvivV8KwrNsnnICJR5l0PSBqBYAZC6surya Nk8BJ1fXGoq5nHt2nfXsDCpX494nDkJduTz03PFLZ3Vj642U97kg7SwQV9oTK2WX115dzag-- X-Yahoo-Newman-Id: 131826.88672.bm@smtp138.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: HXWoyZwVM1lMr31sNwbZhXpZ7tivdiF.vFwT8c1nqJeV1op gOra15RlhD6QGPcKmIlZXEPVNW_OxfQAPlmeQAYlQ0H7yhaiaQeE6onYf9Vk tkzAx5br5x_z19BArcX73Skk28p57FRX6LNYFqoO.b.eEysXkvzOsvVtnW1k alowzuX8JHxhZFL1fFKtK2p2iuFfZYEc6TUSesX2zdZXpLqF7fN.cBNal7LG ylpcmB_kp1qD7aHrQZiYNoyEtJEXYz6trcAi5_QdW7JWIrROQa1OCANr05QG c6tYDd2GcLUx6ScljeZj.vwA7YUjzqYs9chPnPfCgdUJqH.p_9ZwQa0RufvR gV7u.q1EOv_iEKN5vV3NR29kLeJO8EpQd_OQ2fxW4X3FqDrQLxF7LuH6hiQB rpvivV8KwrNsnnICJR5l0PSBqBYAZC6suryaNk8BJ1fXGoq5nHt2nfXsDCpX 494nDkJduTz03PFLZ3Vj642U97kg7SwQV9oTK2WX115dzag-- X-Yahoo-SMTP: opAkk_CswBAce_kJ3nIPlH80cJI- cc: Zsh hackers list In-reply-to: <20170912212519.3d873212@ntlworld.com> From: Oliver Kiddle References: <20170911215115.6aa27dec@ntlworld.com> <20170912212519.3d873212@ntlworld.com> To: Peter Stephenson Subject: Re: PATCH: [key]=value syntax, work in progress MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30373.1505294043.1@thecus.kiddle.eu> Date: Wed, 13 Sep 2017 11:14:04 +0200 Message-ID: <30374.1505294044@thecus.kiddle.eu> 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 .