From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13898 invoked from network); 17 Mar 2008 01:00:06 -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.6 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; 17 Mar 2008 01:00:06 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 55205 invoked from network); 17 Mar 2008 00:59:58 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Mar 2008 00:59:58 -0000 Received: (qmail 9307 invoked by alias); 17 Mar 2008 00:59:55 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 24722 Received: (qmail 9287 invoked from network); 17 Mar 2008 00:59:54 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 17 Mar 2008 00:59:54 -0000 Received: from vms046pub.verizon.net (vms046pub.verizon.net [206.46.252.46]) by bifrost.dotsrc.org (Postfix) with ESMTP id 0915C80307F7 for ; Mon, 17 Mar 2008 01:59:49 +0100 (CET) Received: from torch.brasslantern.com ([71.116.105.150]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2-6.01 (built Apr 3 2006)) with ESMTPA id <0JXU008CYO3NPQRF@vms046.mailsrvcs.net> for zsh-workers@sunsite.dk; Sun, 16 Mar 2008 19:59:48 -0500 (CDT) Received: from torch.brasslantern.com (localhost.localdomain [127.0.0.1]) by torch.brasslantern.com (8.13.1/8.13.1) with ESMTP id m2H0xkLP010429 for ; Sun, 16 Mar 2008 17:59:47 -0700 Received: (from schaefer@localhost) by torch.brasslantern.com (8.13.1/8.13.1/Submit) id m2H0xkJ4010428 for zsh-workers@sunsite.dk; Sun, 16 Mar 2008 17:59:46 -0700 Date: Sun, 16 Mar 2008 17:59:46 -0700 From: Bart Schaefer Subject: Re: ${a[(i)pattern]} if a=() In-reply-to: <20080316232337.GB4910@sc.homeunix.net> To: Zsh hackers list Message-id: <080316175946.ZM10427@torch.brasslantern.com> MIME-version: 1.0 X-Mailer: OpenZMail Classic (0.9.2 24April2005) Content-type: text/plain; charset=us-ascii References: <080316105924.ZM843@torch.brasslantern.com> <200803162157.m2GLv4Mw003473@pws-pc.ntlworld.com> <20080316232337.GB4910@sc.homeunix.net> Comments: In reply to Stephane Chazelas "Re: ${a[(i)pattern]} if a=()" (Mar 16, 11:23pm) X-Virus-Scanned: ClamAV 0.91.2/6267/Mon Mar 17 00:21:46 2008 on bifrost X-Virus-Status: Clean On Mar 16, 11:23pm, Stephane Chazelas wrote: } } > 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: } } matching key found is the result. On failure substitutes one more } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } than the last currently valid index, as discussed under the } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ } description of `r'. } ^^^^^^^^^^^^^^^^^^^ The reason we're getting into trouble here is because there is *no* valid index when the array is empty. 0 is no longer a "currently valid index", so to return "one more than the last" is in some sense also invalid, and zero is the only index that is always invalid (barring KSH_* behavior). My personal opinion is that Stephane has the right of it here, and this empty-array case is just one that we missed way back when we added the "missing (i) falls of the top end" behavior. However, another way out may be to return -1 for (i) on an empty array. Then it's "valid" for appending to the array, but distinguishable from matching the first element. That would be kind of a strange edge case, though, because the $a[(i)] < $#array test for presence of an element would still break.