Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Implement an "array index" subscript flag



Ah thanks for clarifying that. I think we're all on the same page.


I... tried to investigate this, but I've only got as far as finding the SCANPM_WANTKEYS constant, which seems relevant. Not really sure where the actual lookup is implemented.

________________________________
From: dana <dana@xxxxxxx>
Sent: Friday, 8 June 2018 4:15:13 PM
To: zsh-workers@xxxxxxx
Cc: Michael Milton
Subject: Re: Implement an "array index" subscript flag

On 8 Jun 2018, at 00:46, Michael Milton <michael.milton@xxxxxxxxxxxxxx> wrote:
>This produces no output:
>arr=([1]=a [2]=b)
>keys=${arr[(k)@]}
>echo $keys

You're talking about the (k) subscript flag; i meant the (k) expansion flag. See
the hypothetical example in my earlier reply for how the latter works (just use
an association instead of an array). The former isn't relevant here (array
indexes aren't useful as patterns anyway), but it works like this:

  % local -A assoc=( 'a*' val1 '*a' val2 )
  % print ${assoc[(k)abc]}
  val1
  % print ${assoc[(k)cba]}
  val2

If the (k) expansion flag were made to work on indexed arrays it would
definitely not need to do any pattern matching.

dana



Messages sorted by: Reverse Date, Date, Thread, Author