Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expanding nameref target?
- X-seq: zsh-workers 51488
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Mikael Magnusson <mikachu@xxxxxxxxx>, zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: expanding nameref target?
- Date: Tue, 28 Feb 2023 09:47:17 +0100
- Archived-at: <https://zsh.org/workers/51488>
- In-reply-to: <CAH+w=7bFo3Ph7MTE5EkFfk5wYLY00MEHiQHOt9ZNWhem4fwLVw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAHYJk3TgMpb0Z3cmLhZ-EQ5p8o_q9G7KE-mF1UAGguoOY=cQeQ@mail.gmail.com> <CAH+w=7bzkkKAg+TF9itdSeffk4VjfJWQnBgXonLn_cRA=ETrnQ@mail.gmail.com> <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author