zsh-workers
 help / color / mirror / code / Atom feed
* Implement an "array index" subscript flag
@ 2018-06-08  1:37 Michael Milton
  2018-06-08  5:16 ` dana
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Milton @ 2018-06-08  1:37 UTC (permalink / raw)
  To: zsh-workers


[-- 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 --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-06-08  8:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-08  1:37 Implement an "array index" subscript flag Michael Milton
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

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).