From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15343 invoked from network); 3 Apr 2005 19:59:08 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 3 Apr 2005 19:59:08 -0000 Received: (qmail 718 invoked from network); 3 Apr 2005 19:59:02 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 3 Apr 2005 19:59:02 -0000 Received: (qmail 4066 invoked by alias); 3 Apr 2005 19:58:59 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21091 Received: (qmail 4056 invoked from network); 3 Apr 2005 19:58:59 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 3 Apr 2005 19:58:59 -0000 Received: (qmail 413 invoked from network); 3 Apr 2005 19:58:59 -0000 Received: from vms046pub.verizon.net (206.46.252.46) by a.mx.sunsite.dk with SMTP; 3 Apr 2005 19:58:55 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms046.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IED00LS8ZI481U5@vms046.mailsrvcs.net> for zsh-workers@sunsite.dk; Sun, 03 Apr 2005 14:58:53 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j33Jwq23004283 for ; Sun, 03 Apr 2005 12:58:52 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j33JwqJt004282 for zsh-workers@sunsite.dk; Sun, 03 Apr 2005 12:58:52 -0700 Date: Sun, 03 Apr 2005 19:58:51 +0000 From: Bart Schaefer Subject: Re: ${(kv)foo[bar]} In-reply-to: <200504032200.41605.arvidjaar@newmail.ru> To: zsh-workers@sunsite.dk Message-id: <1050403195852.ZM4281@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <200504031435.19457.arvidjaar@newmail.ru> <1050403174903.ZM4196@candle.brasslantern.com> <200504032200.41605.arvidjaar@newmail.ru> Comments: In reply to Andrey Borzenkov "Re: ${(kv)foo[bar]}" (Apr 3, 10:00pm) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Apr 3, 10:00pm, Andrey Borzenkov wrote: } Subject: Re: ${(kv)foo[bar]} } } Although it is rather hard to understand why ${(kv)opt_args[(i)--media]} } should work and ${(kv)opt_args[--media]} not. The rationalization is that with [(i)...] the subscript is a pattern, so you may not know in advance what it's going to match, and therefore it is useful to be able to return both the key and the value. [(i)--media] is a degenerate case where the pattern is a plain string. Without the (i), the subscript is always a plain string and therefore known, and you don't need to be able to expand it. The real reason, as I said, is that the implementation of subscripting with [(i)...] does a scan of the hash keys rather than a simple hash lookup; it's got code that's shared with (R) and (I) and therefore is designed to return an array. Implementing subscripting with a full scan in the ordinary case just for (kv) would foil the reason for using a hash table to begin with.