zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Oliver Kiddle <opk@zsh.org>
Cc: Mikael Magnusson <mikachu@gmail.com>, zsh workers <zsh-workers@zsh.org>
Subject: Re: expanding nameref target?
Date: Tue, 28 Feb 2023 09:55:18 -0800	[thread overview]
Message-ID: <CAH+w=7aaU4k+CCQJUXyxrYrWDzDEO8AHPFFv-Gqu+rSgp9SPzw@mail.gmail.com> (raw)
In-Reply-To: <60026-1677574037.450652@BS_8.Gg9A.ql-t>

On Tue, Feb 28, 2023 at 12:47 AM Oliver Kiddle <opk@zsh.org> wrote:
>
> Bart Schaefer wrote:
> > In ksh emulation (and history disabled), I have this working:
> >
> > % typeset -n foo=bar
> > % echo ${!foo}
> > bar
>
> Supporting ${!foo} is useful for ksh (and bash) compatibility so that
> sounds good. There are also other forms such as ${!name[@]}.

There are some significant differences between bash and ksh regarding
${!...}, I have a patch for subst.c that documents this in comments.
The simplest one is that ${!scalar} in bash works like ${(P)scalar} in
zsh, whereas in ksh it just substitutes the parameter's own name.

We already supported ksh ${!foo[@]} for associative arrays, I bolted
nameref handling into that code path (in addition to the zsh flags
path).  However, that's explicitly (and commented-ly) enabled only in
ksh emulation.  We don't support fetching the array of (normal) array
indexes anywhere, I haven't tried to add that.

> > However, that's pretty clumsy because of history expansion, so I'm
> > proposing the following for zsh native mode:
> >
> > % typeset -n foo=bar
> > % echo ${(?)foo}
>
> I would question whether it's really sufficiently useful to warrant
> that.

It does seem unlikely to be something wanted during an interactive
session.  How about if I leave it with just ${(!)foo} instead of
consuming (?) as well?

> I'm inclined to suspect that anyone who thinks they need ${!foo}
> has probably missed the point of namerefs. Unless they are writing
> something that is meta in nature to begin with

I presumed Mikael had a use-case or he wouldn't have asked about it.
It seems odd to have it available but only usable in ksh mode (e.g.,
${!...} is historically a synonym for ${(k)...}, but that doesn't make
sense for namerefs).

> > As an extension (more by accident than by design but possibly useful):
> >
> > % echo ${(?)options}
> > zsh/parameter
>
> Doesn't that lead to a conflict for a nameref defined in a module - do
> you get the module name or the target of the nameref?

You get the module until the feature is loaded, and then you get the
target of the nameref.


      parent reply	other threads:[~2023-02-28 17:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 13:07 Mikael Magnusson
2023-02-21 15:59 ` Bart Schaefer
2023-02-28  5:00   ` Bart Schaefer
2023-02-28  8:47     ` Oliver Kiddle
2023-02-28 10:33       ` Mikael Magnusson
2023-02-28 18:01         ` Bart Schaefer
2023-02-28 17:55       ` 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=7aaU4k+CCQJUXyxrYrWDzDEO8AHPFFv-Gqu+rSgp9SPzw@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=mikachu@gmail.com \
    --cc=opk@zsh.org \
    --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).