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

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[@]}.

> 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. 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 like the describe-params
function that recently circulated on the -users list. ${!foo} may give
you the name of a variable that is hidden by a local variable so you
don't want to rely on it if you want your code to be robust.

So my view is that I wouldn't bother expending one of the few remaining
flag characters on it.

> 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?

Oliver


  reply	other threads:[~2023-02-28  8:47 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 [this message]
2023-02-28 10:33       ` Mikael Magnusson
2023-02-28 18:01         ` Bart Schaefer
2023-02-28 17:55       ` Bart Schaefer

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=60026-1677574037.450652@BS_8.Gg9A.ql-t \
    --to=opk@zsh.org \
    --cc=mikachu@gmail.com \
    --cc=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).