Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parameter flags and subscripts and references
- X-seq: zsh-workers 54079
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Parameter flags and subscripts and references
- Date: Thu, 13 Nov 2025 20:05:21 -0800
- Archived-at: <https://zsh.org/workers/54079>
- In-reply-to: <CAGdYchusmSr2wwRJDLsPGzj56SaNS2m5U1Tf5_HwYj9qa0=jEg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7Y5EVK3NE0EsR3WkbDvgGVSHc_FFpscvmSuZ3=T-dq_2A@mail.gmail.com> <CAGdYchusmSr2wwRJDLsPGzj56SaNS2m5U1Tf5_HwYj9qa0=jEg@mail.gmail.com>
On Thu, Nov 13, 2025 at 6:22 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> print $parameters[nr]
>> nameref-nameref
>>
>> This happens because getpmparameter() presumes that gethashnode2() and
>> getparamnode() will return different results, but resolve_nameref()
>> called from getparamnode() recognizes that a subscripted referent must
>> be the stopping point, and so returns its input.
>
> There are many issues with references to subscripted variables. I worked on that a few months ago. I'll have to resume that work.
Most of these are probably very rarely used cases, so I wouldn't call
this urgent.
Related:
% array=(a b c)
% typeset -n r1=array
% print ${r1[2]}
b
% typeset -n r2='r1[2]'
% print $r2
r
$r2 is implicitly doing ${(!)r1[2]} because of the "stop at
subscripts" behavior. This could at least be documented (note to
self).
>> The question is, what should the result be?
>
> Given that "$parameters[path[2]]" expands to the empty string, I would expect "$parameters[nr]" to expand to just "nameref". If we ever change "parameters" to return some non-empty value "FOO" for the former then the latter should return "nameref-FOO".
This originated from Daniel's question:
> Should ${(t!)foo} expand to "nameref-scalar" whenever ${parameters[foo]} does?
Maybe the answer is that ${parameters[foo]} should *never* expand to
"nameref-scalar" and should just stop at "nameref" like (t!) does,
regardless of what "foo" represents.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author