zsh-workers
 help / color / mirror / code / Atom feed
From: dana <dana@dana.is>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
Cc: Michael Milton <michael.milton@unimelb.edu.au>
Subject: Re: Implement an "array index" subscript flag
Date: Fri, 8 Jun 2018 01:15:13 -0500	[thread overview]
Message-ID: <BD139A31-B869-4F98-8B4C-4018461287CA@dana.is> (raw)
In-Reply-To: <SYXPR01MB1069C119157F5362DB60180CBA7B0@SYXPR01MB1069.ausprd01.prod.outlook.com>

On 8 Jun 2018, at 00:46, Michael Milton <michael.milton@unimelb.edu.au> 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


  reply	other threads:[~2018-06-08  6:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-08  1:37 Michael Milton
2018-06-08  5:16 ` dana
2018-06-08  5:46   ` Michael Milton
2018-06-08  6:15     ` dana [this message]
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=BD139A31-B869-4F98-8B4C-4018461287CA@dana.is \
    --to=dana@dana.is \
    --cc=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).