From: Michael Milton <michael.milton@unimelb.edu.au>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Implement an "array index" subscript flag
Date: Fri, 8 Jun 2018 01:37:59 +0000 [thread overview]
Message-ID: <SYXPR01MB1069D97AEB4D3F17C1E1E43DBA7B0@SYXPR01MB1069.ausprd01.prod.outlook.com> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1005 bytes --]
Hi all,
A useful feature for zsh would be the ability to convert an array into an array of keys/indexes for that array. For example, converting (a b c d) into (1 2 3 4)
Bash has a syntax for this, with the ${!array[@]} expansion, e.g.
vals=(a b c d)
keys=${!ids[@]}
Could we perhaps add another "Subscript Flag" to zsh, such that it evaluates the array into its indexes? For example, it might be ${(x)array[@]}, such that you could use it like this:
vals=(a b c d)
keys=${(x)ids[@]}
I suspect there is some desire for a feature like this, because there is a StackExchange question on the subject for zsh: https://unix.stackexchange.com/questions/334048/obtain-the-index-of-the-array, as well as a very high profile question for bash: https://stackoverflow.com/questions/6723426/looping-over-arrays-printing-both-index-and-value.
I'd be happy to contribute such a feature but I'm not sure what the contribution process actually is.
[1487806188587_VLSCI-MelbBioinfo-sign.png]
[-- Attachment #1.2: Type: text/html, Size: 3117 bytes --]
[-- Attachment #2: Outlook-1487806188.png --]
[-- Type: image/png, Size: 32868 bytes --]
next reply other threads:[~2018-06-08 1:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-08 1:37 Michael Milton [this message]
2018-06-08 5:16 ` dana
2018-06-08 5:46 ` Michael Milton
2018-06-08 6:15 ` dana
2018-06-08 6:27 ` Michael Milton
2018-06-08 8:25 ` Peter Stephenson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=SYXPR01MB1069D97AEB4D3F17C1E1E43DBA7B0@SYXPR01MB1069.ausprd01.prod.outlook.com \
--to=michael.milton@unimelb.edu.au \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).