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

On 2/28/23, 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[@]}.
>
>> 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.

What about (PP)? There is some precedent for doubling a flag to
disable its effect. The downside is that (PP) already works and is
treated like (P) but...

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

Does a nameref defined in a module before the module is loaded
actually have a target yet?

-- 
Mikael Magnusson


  reply	other threads:[~2023-02-28 10:34 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 [this message]
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='CAHYJk3R+t1J3foARgOXCLp5LLfR2Qx=zwonH_Fo2-XoDccuu7w@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=opk@zsh.org \
    --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).