Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: expanding nameref target?
- X-seq: zsh-workers 51489
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Oliver Kiddle <opk@xxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: expanding nameref target?
- Date: Tue, 28 Feb 2023 11:33:49 +0100
- Archived-at: <https://zsh.org/workers/51489>
- In-reply-to: <60026-1677574037.450652@BS_8.Gg9A.ql-t>
- 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> <60026-1677574037.450652@BS_8.Gg9A.ql-t>
On 2/28/23, Oliver Kiddle <opk@xxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author