From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6986 invoked from network); 16 Mar 2008 23:24:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 Mar 2008 23:24:01 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 19788 invoked from network); 16 Mar 2008 23:23:54 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Mar 2008 23:23:54 -0000 Received: (qmail 8438 invoked by alias); 16 Mar 2008 23:23:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24721 Received: (qmail 8419 invoked from network); 16 Mar 2008 23:23:49 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 16 Mar 2008 23:23:49 -0000 Received: from n068.sc1.he.tucows.com (smtpout0130.sc1.he.tucows.com [64.97.136.130]) by bifrost.dotsrc.org (Postfix) with ESMTP id 2567C80307F7 for ; Mon, 17 Mar 2008 00:23:43 +0100 (CET) Received: from sc1-out08.emaildefenseservice.com (64.97.139.2) by n068.sc1.he.tucows.com (7.2.069.1) id 4769316E00EFFB16; Sun, 16 Mar 2008 23:23:39 +0000 X-SpamScore: 2 X-Spamcatcher-Summary: 2,0,0,c4b5118131db118f,3cab90302003cb79,stephane_chazelas@yahoo.fr,-,RULES_HIT:355:379:599:601:945:973:982:988:989:1260:1277:1311:1312:1313:1314:1345:1358:1359:1437:1515:1516:1518:1519:1534:1541:1593:1594:1595:1596:1711:1730:1747:1766:1792:1801:2198:2199:2393:2553:2559:2562:2828:2899:3027:3353:3622:3865:3866:3867:3868:3869:3871:3872:3873:3874:4605:5007:6119:6261,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL: none,DNSBL:none X-Spamcatcher-Explanation: Received: from sc.homeunix.net (client-82-26-171-1.edin.adsl.virgin.net [82.26.171.1]) by sc1-out08.emaildefenseservice.com (Postfix) with ESMTP; Sun, 16 Mar 2008 23:23:38 +0000 (UTC) Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1Jb2CX-0000NE-RR; Sun, 16 Mar 2008 23:23:37 +0000 Date: Sun, 16 Mar 2008 23:23:37 +0000 From: Stephane Chazelas To: Peter Stephenson Cc: Zsh hackers list Subject: Re: ${a[(i)pattern]} if a=() Message-ID: <20080316232337.GB4910@sc.homeunix.net> Mail-Followup-To: Peter Stephenson , Zsh hackers list References: <080316105924.ZM843@torch.brasslantern.com> <200803162157.m2GLv4Mw003473@pws-pc.ntlworld.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <200803162157.m2GLv4Mw003473@pws-pc.ntlworld.com> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.91.2/6266/Sun Mar 16 22:47:23 2008 on bifrost X-Virus-Status: Clean On Sun, Mar 16, 2008 at 09:57:04PM +0000, Peter Stephenson wrote: > Bart Schaefer wrote: > > On Mar 16, 10:20am, Bart Schaefer wrote: > > } > > } } $ zsh -f -c 'a=(); echo ${a[(i)a]}' > > } } 0 > > } > > } Hmm ... it seems it has always returned zero when the array is empty. > > } It would seem to make more sense for it to return 1, but I'm worried > > } there are other unforseen consequences. > > I think it's supposed to return 0 because it didn't match. 1 indicates > it matched the first array element. [...] According to the manual: i Like `r', but gives the index of the match instead; this may not be combined with a second argument. On the left side of an assignment, behaves like `r'. For associative arrays, the key part of each pair is compared to the pattern, and the first matching key found is the result. On failure substitutes one more ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ than the last currently valid index, as discussed under the ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ description of `r'. ^^^^^^^^^^^^^^^^^^^ That's why you get: $ zsh -f -c 'a=(b); echo ${a[(i)a]}' 2 And I thought you should get 1 (1 more than the first valid index) $ zsh -f -c 'a=(); echo ${a[(i)a]}' 1 -- Stéphane