From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13899 invoked from network); 21 Sep 1999 05:00:53 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 21 Sep 1999 05:00:53 -0000 Received: (qmail 25605 invoked by alias); 21 Sep 1999 04:59:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7972 Received: (qmail 25597 invoked from network); 21 Sep 1999 04:59:56 -0000 From: "Bart Schaefer" Message-Id: <990921045934.ZM13380@candle.brasslantern.com> Date: Tue, 21 Sep 1999 04:59:34 +0000 In-Reply-To: Comments: In reply to Tanaka Akira "assoc array assignment problem." (Sep 21, 10:37am) References: X-Mailer: Z-Mail (5.0.0 30July97) To: Tanaka Akira , zsh-workers@sunsite.auc.dk Subject: Re: assoc array assignment problem. MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 21, 10:37am, Tanaka Akira wrote: } Subject: assoc array assignment problem. } } Z(2):akr@localhost% Src/zsh -f } localhost% typeset -A arr } localhost% a='$b' } localhost% b='c' } localhost% arr[$a]=d } localhost% print -lr - ${(kv)arr} } c } d } localhost% } } Hm. Variable expansion is performed twice. This is not an associative array problem; it affects all arrays. Note: zagzig<17> q=() zagzig<18> g=7 zagzig<19> f='$g' zagzig<20> q[$f]=seven zagzig<21> print $#q $q 7 seven zagzig<22> The first substitution happens at the expected time, during evaluation of the line. The second one happens at execute time in addvars() -- assignment is implemented as if `x=y somecommand` where somecommand is null. addvars() calls setsparam(), which discovers that there is no parameter named "q[$g]" and therefore creates "q" and then makes a call to getvalue() to retrieve a Value structure for the parameter that it just created. getvalue() then expands $g (as it would for ${q[$g]} in which the stuff inside the ${ } has _not_ previously been expanded) and you get the effect above. And you can't even protect it with double-quoting, though using single quotes counterintuitively (but expectedly, given the explaination above) produces the desired result: zagzig<26> arr['$a']=d zagzig<27> print -lr - ${(kv)arr} $x d zagzig<28> I really have no idea when this got introduced. It might have something to do with zsh-workers/4826 and follow-ons, back last year; 3.1.5-pws-4 would be it, but I no longer have anything that old around to try. The right thing would be for the parser to know that it shouldn't expand inside the [] on the left-hand side of an assignment, thereby delaying the one interesting expansion to getvalue(); but that may be a bit too much to bite off ... -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com