From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4215 invoked by alias); 8 Jun 2018 05:16:26 -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: List-Unsubscribe: X-Seq: 42950 Received: (qmail 18537 invoked by uid 1010); 8 Jun 2018 05:16:26 -0000 X-Qmail-Scanner-Diagnostics: from mail-io0-f171.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.223.171):SA:0(-1.9/5.0):. Processed in 2.005322 secs); 08 Jun 2018 05:16:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, SPF_PASS,T_DKIMWL_WL_MED,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: dana@dana.is X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dana-is.20150623.gappssmtp.com; s=20150623; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cjH2RGYEEqMinGogPk51BnlywegGW4swekV7qeRvXIU=; b=1hoU0tBnVCI3LPYMTKOX4UxPW+2s0D7b3CjSdjx4DifDrqE3LVQo2J9s73cIWLhRxv k28Empd4leV76QSegjad/IDCaVaU4pnShGOWShwAVw71cX9cNB9DlHOz/PEcB43du1cm H9cfsCUFN16Zin1ym5YBftFuDVDnlSr5VaqjHDI5rrNI+YBHAuXPEqByQyevLsRsueYj kiOEwcrOSa3kAlNVG79mWGUPm1ZCb6idv+SNczObH3IaF30BJGKbE4vJLmPsAh9D19bV A7zQl7b/wvAiv6lrmrku2N51vtlUX67RX5q+XOJERkIedY9sEoNy8H94SOHDK3EaaBH8 PkiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=cjH2RGYEEqMinGogPk51BnlywegGW4swekV7qeRvXIU=; b=diwOTDTF6tNMY+mNdmU6JBuMewZqdJ87DiM87l6jGRLI7Srck5aKzX7YPADhBxlMBq alXpcggwW3Cup/yWnxzzm39+JJC4OX48RubpLlWxU+ry2aR94ebnsf+HoXloN+CkpmhZ AocOgC2HZ6AUiRsTX4LWhuEvf603kX1zyt1A7zScwaXQgKk86mymED3YU08NOb/wBsvm lNqxG0yx1JQ1KGhFLERqck3mGAgQ4K9crIIO6++7Azj34I/gCPWkUsypZ/CHe6Y+xuW+ pjwm6WOiBFpfRuUgaVxXKJNby8TghA17JkgpAHO9iyHhJL4c7wQOdkwobWXorUs/IKXV r3cA== X-Gm-Message-State: APt69E2m5iAEr+38Y6D5Pq1gaDWA5hM+0lpQIsnPzi2MsC2//SqdCiwm y7Q0h7RqYadc5ngV36k3apyw6VLf1TA= X-Google-Smtp-Source: ADUXVKLJ9YuVavATmCYwWC5LQ5dnIcdO35MCeoLO7inSd67DPI7JcFaZ8qTo3N65m8+0wOMR4NovZA== X-Received: by 2002:a6b:fb04:: with SMTP id h4-v6mr4370508iog.193.1528434981387; Thu, 07 Jun 2018 22:16:21 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: Implement an "array index" subscript flag From: dana In-Reply-To: Date: Fri, 8 Jun 2018 00:16:20 -0500 Cc: Michael Milton Content-Transfer-Encoding: quoted-printable Message-Id: <075A01C0-8DA7-4D1B-8553-1C1C2B66D0F2@dana.is> References: To: "zsh-workers@zsh.org" X-Mailer: Apple Mail (2.3273) On 7 Jun 2018, at 20:37, Michael Milton = wrote: >A useful feature for zsh would be the ability to convert an array into = an array >of keys/indexes for that array.... Bash has a syntax for this, with the >${!array[@]} expansion zsh actually has the (k) flag for this, but it only works on = associations. zsh also supports the ! syntax (which bash 3 borrowed from ksh93) when in = ksh- emulation mode, but since it's effectively an alias for (k) it *also* = works only on associations. To be clear, in both bash 4 and ksh93 it works as = expected on both. I feel like the intuitive thing would be for (k) and (v) to work on = arrays equivalently to the way they work on associations. In other words... % arr=3D( foo bar baz ) % print ${(k)arr} 1 2 3 % print ${(kv)arr} 1 foo 2 bar 3 baz Looking at the manual, it seems to me that the current effect of those = two flags on arrays is actually undefined (except when used in conjunction with a subscript), so... would that not be a reasonable change to make, if = someone were inclined? Looks like Oliver was considering exactly that, once upon a time: http://www.zsh.org/mla/workers/2004/msg00226.html In the mean time, though, like the Stack Exchange link says =E2=80=94 = since zsh doesn't support sparse arrays, i think {1..$#arr} is almost exactly equivalent = to (the hypothetical) ${(k)arr}. dana