Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: expanding nameref target?



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