From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10846 invoked by alias); 2 Nov 2015 19:44:20 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 20878 Received: (qmail 1331 invoked from network); 2 Nov 2015 19:44:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1446493069; bh=BuM4+VHCUfZxWVF0zCJIkATtEYmUU2hsrCbPZdaQHZk=; h=From:To:In-Reply-To:References:Subject:Date; b=o7KsCFoyIfHgE96t/UhNaoMeiQyIxpquYoY7Rwl1CvCigBM//2fAo04zbAXM2hWoG ocQigKR8Oy0N49uHzE2wSOq8xRlCo47RrqSCMidGkyYkV3z+SSid+4Xz7CO6aWNbNX tNTIZR5E2THYw5in3G7Vjtum+VrOULvLeHg4ep3s= From: ZyX To: Ray Andrews , "zsh-users@zsh.org" In-Reply-To: <5637AC27.8010007@eastlink.ca> References: <56369C7B.2030604@eastlink.ca> <1237641446422150@web6m.yandex.ru> <5636B333.8060300@eastlink.ca> <151101190842.ZM16752@torch.brasslantern.com> <5636D99F.2030807@eastlink.ca> <151101225100.ZM16882@torch.brasslantern.com> <563784B5.3040901@eastlink.ca> <151102082808.ZM17640@torch.brasslantern.com> <5637AC27.8010007@eastlink.ca> Subject: Re: easy calling of associative array? MIME-Version: 1.0 Message-Id: <280101446493068@web5o.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 02 Nov 2015 22:37:48 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=koi8-r 02.11.2015, 22:03, "Ray Andrews" : > On 11/02/2015 08:28 AM, Bart Schaefer wrote: >> š} #$3=${(P)${:-${1}[$2]}} #nothing works > > Pardon, that was an obvious mistake. Too much thrashing around with 'eval'. >> šSame assignment-syntax problem. >> >> ššššššset_v () { >> šššššššštypeset -g "${1}[$2]=$3" # quotes so [ ] isn't globbing >> šššššš} >> >> šHere you don't need the (P) indirection because ${1} and $2 are both >> šexpanded before being passed to typeset, so you already extracted the >> šname that was passed in $1. > > ... and that's nicely readable too--the sort of syntax that seems > intuitive, as I > mentioned. I won't say this is all clear in my mind, but it's > at least tractable. One further question: I've never seen 'typeset' > used to refer > to anything but a simple variable. I note that the above does not work > without > the 'typeset -g' so what does that accomplish? I've never thought of the > positional parameters and being typeset-able. I get the feeling it is a > future > problem solver. Typeset variant has unresolved problems with `$2` escaping. Writing `${(q)2}` works here, but I have no idea why it works. Note: when trying to use any of the functions, try with keys `abc]def` and `abc def` (two spaces inside). First collects most of the errors. >> šAlso note I'm ignoring all possible error checking, e.g. if $1 is not >> šan identifier (in the worst case, contains an "="), things go badly. > > Sure, it's naive at this point. I don't yet think past that. >> šI'm not exactly sure what you're wanting as either output or exit >> šstatus here, but except that I'd recommend [[ ]] instead of [ ] as >> šthe test syntax, what you wrote for "this works" is sensible. > > Ok. I don't pay enough attention to the difference. > > BTW, as a point of list etiquette: Responding to most posts I let my > lines wrap > but resonding to yours, which seem to alway have fixed line width, I try to > match that style, but looking at the returned posts from the list, they > sometimes > sproing badly. Should I try to keep to your width, or just let lines wrap? >>