Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Implement an "array index" subscript flag
- X-seq: zsh-workers 42954
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: Implement an "array index" subscript flag
- Date: Fri, 8 Jun 2018 09:25:30 +0100
- Cms-type: 201P
- Dkim-filter: OpenDKIM Filter v2.11.0 mailout1.w1.samsung.com 20180608082534euoutp01b2c1ef299c36f5e51082c0bc8cb30f33~2Idfn_W_I2267322673euoutp01w
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1528446334; bh=aQa8mkcTCQ6X9E5mwXRV2RxviH0BzuNSnLpFXISmVyI=; h=Date:From:To:Subject:In-Reply-To:References:From; b=hbnhOKt3mtvYDXbQ8QKWX/wdjrkMlmHqhiyKjOhqi1mfw545kLIXFuh8TM1Rq6DsY BQJma1A6GS2/2zApPOb+iGComUmKQFCFbhsDmkig3wTlwqImznWpks9Gg32FcPcZNM QaaR/O2msLrrRc65rJ6YxrYvTFgpWbdKp6bvN1+M=
- In-reply-to: <075A01C0-8DA7-4D1B-8553-1C1C2B66D0F2@dana.is>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- Organization: SCSC
- References: <SYXPR01MB1069D97AEB4D3F17C1E1E43DBA7B0@SYXPR01MB1069.ausprd01.prod.outlook.com> <CGME20180608051657epcas3p22a9527a1001a78a9d76f68e19e32d647@epcas3p2.samsung.com> <075A01C0-8DA7-4D1B-8553-1C1C2B66D0F2@dana.is>
On Fri, 8 Jun 2018 00:16:20 -0500
dana <dana@xxxxxxx> wrote:
> On 7 Jun 2018, at 20:37, Michael Milton
> <michael.milton@xxxxxxxxxxxxxx> 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.
>
> I feel like the intuitive thing would be for (k) and (v) to work on
> arrays equivalently to the way they work on associations.
This is reasonable, as far as I can see, but the reason this isn't
an issue in zsh is that unlike bash arrays are really arrays --- in
bash they're basically linked lists, so stored sparsely. So in zsh
the simple {1..${#array}} is good enough. "Empty" array elements
in the middle contain a zero length string. If you really need
sparse storage you have to use an associative array.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author