zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: [PATCH 3/3] Documentation for named references
Date: Wed, 8 Feb 2023 13:28:46 -0800	[thread overview]
Message-ID: <CAH+w=7am75HJbYQFxV22dAxdgPK12s2b24GnnCN8pMNh-bPepA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZBjhMVmLk=Rgf6PSF91nd_5OSoW=o068Rg4r4F39poJA@mail.gmail.com>

On Tue, Feb 7, 2023 at 8:53 AM Bart Schaefer <schaefer@brasslantern.com> wrote:
>
> ${(P)name} is defined to expand $name and then treat the string value
> as a further parameter name.  What would it mean to expand a named
> reference without resolving it?  Just ignore that it's a named
> reference and treat it as a scalar?

That last is in fact what bash does with ${!name} (when not a nameref,
it's like ${(P)name}.  I suppose it would be nice to have a way to
expand the name to which a named reference points, but I'm not sure
overloading (P) is the best way.

There's a slew of other special bash meanings of parameter references
that start with "!":
  ${!name*} == ${(k)parameters[(I)name*]}
  ${!name@} == ${(@k)parameters[(I)name*]}
  ${!name[*]} == ${(k)name} (but indexes of ordinary arrays, too)
  ${!name[@]} == ${(@k)name} (ditto)

Indexes of ordinary arrays aren't very useful in zsh because arrays
are not sparse, every element is at least empty string, but you can
get the indexes of all non-empty elements with
  ${(*)name//(#m)?*/${name[(ie)$MATCH]}}


      reply	other threads:[~2023-02-08 21:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06  2:26 Bart Schaefer
2023-02-07  0:56 ` Daniel Shahaf
2023-02-07  3:25   ` Bart Schaefer
2023-02-07 10:51     ` Daniel Shahaf
2023-02-07 16:53       ` Bart Schaefer
2023-02-08 21:28         ` Bart Schaefer [this message]

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='CAH+w=7am75HJbYQFxV22dAxdgPK12s2b24GnnCN8pMNh-bPepA@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --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).