From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29157 invoked from network); 16 Mar 2008 21:57:50 -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 21:57:50 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 86764 invoked from network); 16 Mar 2008 21:57:43 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 Mar 2008 21:57:43 -0000 Received: (qmail 13071 invoked by alias); 16 Mar 2008 21:57:38 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24720 Received: (qmail 13053 invoked from network); 16 Mar 2008 21:57:38 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 16 Mar 2008 21:57:38 -0000 Received: from mtaout02-winn.ispmail.ntl.com (mtaout02-winn.ispmail.ntl.com [81.103.221.48]) by bifrost.dotsrc.org (Postfix) with ESMTP id 796DC80307F7 for ; Sun, 16 Mar 2008 22:57:34 +0100 (CET) Received: from aamtaout02-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com with ESMTP id <20080316220008.YBIM27871.mtaout02-winn.ispmail.ntl.com@aamtaout02-winn.ispmail.ntl.com> for ; Sun, 16 Mar 2008 22:00:08 +0000 Received: from pws-pc.ntlworld.com ([81.107.42.63]) by aamtaout02-winn.ispmail.ntl.com with ESMTP id <20080316215921.MBNF17393.aamtaout02-winn.ispmail.ntl.com@pws-pc.ntlworld.com> for ; Sun, 16 Mar 2008 21:59:21 +0000 Received: from pws-pc (pws-pc [127.0.0.1]) by pws-pc.ntlworld.com (8.14.2/8.14.2) with ESMTP id m2GLv4Mw003473 for ; Sun, 16 Mar 2008 21:57:04 GMT Message-Id: <200803162157.m2GLv4Mw003473@pws-pc.ntlworld.com> From: Peter Stephenson To: Zsh hackers list Subject: Re: ${a[(i)pattern]} if a=() In-Reply-To: Message from Bart Schaefer of "Sun, 16 Mar 2008 10:59:24 MST." <080316105924.ZM843@torch.brasslantern.com> Date: Sun, 16 Mar 2008 21:57:04 +0000 X-Virus-Scanned: ClamAV 0.91.2/6265/Sun Mar 16 20:49:23 2008 on bifrost X-Virus-Status: Clean 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. What has changed is that 0 is now always treated as being a failed matched, instead of being kludged to 1. This agrees exactly, unless I'm missing something, with the original behaviour here, which is a failed match and therefore shouldn't correspond to an index indicating a successful match. The fact we happen to need a genuine index later is a separate issue; the point here is that we haven't found it by reverse-matching the array. I don't see the point in propagating the inability to detect a failed match. The original patch, - [[ $elt -gt $#amenu ]] && elt= + [[ $elt -eq 0 || $elt -gt $#amenu ]] && elt= seems to me a much better solution. The first test means we're off the beginning, the second test off the end. Being able to distinguish both cases is a feature. -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/