From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5278 invoked by alias); 24 Jun 2015 15:04:00 -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: 35591 Received: (qmail 5731 invoked from network); 24 Jun 2015 15:03:56 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=pVCf+HQ07cN0gaZG9bWhT+MAxuF9GLY+P0oQL34Yy/k=; b=SYUaFZ5tF70GGgH+mnMIUoj+7F7O+UuvyS7IEJucDow//cLRyCIjEb/LFT6lu6gn+j XmYZf7jUm5TjDxe/A9imoau1QsV0yfQ8cHuel+kp/U8LKZk3/Ahft7mqnhm4vhyH6Mo4 o6jyl9soL9f+nXPYFuAMi8B3Rpds+WP269hg/a10BnZCAbByK+UoNDwDATsfswF+im4j r0SDXIvmluD7deR2CEIyyaKsJIa9hqBwQ/tBZgVJEpbkdmsM+ZQDqpvRYxOr2VGCGTQf 9lrJ2o9CxZcsyFJJHXgeparO57VXzb2YupT1T6L4BNc9HkCHhF4MGhciPHrFzrMRnNlc IoiQ== X-Gm-Message-State: ALoCoQnIw9nJCexJDLxz1C5IeXJaPqFY5Xu/m7QGuqIfWnvvSDixGXcDaaF1W9INJOg0Gl8olo1s X-Received: by 10.182.230.4 with SMTP id su4mr15731522obc.0.1435158232472; Wed, 24 Jun 2015 08:03:52 -0700 (PDT) From: Bart Schaefer Message-Id: <150624080348.ZM18711@torch.brasslantern.com> Date: Wed, 24 Jun 2015 08:03:48 -0700 In-Reply-To: <20150624101404.71c21adc@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: Typeset with array" (Jun 24, 10:14am) References: <5578996E.3080700@thequod.de> <150610191427.ZM30841@torch.brasslantern.com> <5579C247.1060800@thequod.de> <150611183639.ZM32247@torch.brasslantern.com> <20150612094237.338f79d5@pwslap01u.europe.root.pri> <20150619123930.2688d9e3@pwslap01u.europe.root.pri> <20150621210512.113577a6@ntlworld.com> <20150621213842.621886e0@ntlworld.com> <20150623174719.43eaa1e2@pwslap01u.europe.root.pri> <150623132522.ZM6177@torch.brasslantern.com> <20150624101404.71c21adc@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: "Zsh Hackers' List" Subject: Re: Typeset with array MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Jun 24, 10:14am, Peter Stephenson wrote: } } > This has me trying to think of ways to implement the ksh ([key]=value) } > syntax. } > } > typeset -a varname=([k1]=v1 [k2]=v2) Incidentally, I just stumbled over the bash feature that you can set elements of a regular array this way as well. bash$ array=([0]="a" [2]="b" [1]="") bash$ typeset -p array declare -a array='([0]="a" [1]="" [2]="b")' bash$ I believe someone else already pointed out that looking inside the quoted value for a parenthesized list has its own set of problems. Ksh always creates an associative array with that syntax unless explictly told otherwise, but it accepts it for normal arrays: ksh$ array=([0]="a" [2]="b" [1]="") ksh$ typeset -p array typeset -A array=([0]=a [1]='' [2]=b) ksh$ typeset -a array=([0]="a" [2]="b" [1]="") ksh$ typeset -p array typeset -a array=(a '' b) ksh$ So it really is just the same as mapping the variable name across the values in the list. } However, You could get away with detecting the form until the list is "not detecting"? } expanded: that's now in two different places, addvars and execcmd, but } could easily be made common --- put something in front of the } ecgetlist() that retrieves the array. As long as you detect it before } attempting to glob, to avoid NO_MATCH behaviour, it ought to work. This } is easier as there are no wordcode changes and I can't see any obvious } gotchas. I'm not sure what expansions apply: do k* get expanded at all? } Presumably v* get single word expansion? ksh$ echo D* Doc ksh$ typeset array=([D*]=D*) ksh$ typeset -p array typeset -A array=(['D*']='D*') ksh$ But note: ksh$ typeset -A array=([*]=*) ksh: *: invalid subscript in assignment ksh$