Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parameter flags and subscripts and references
- X-seq: zsh-workers 54088
- 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: Sun, 16 Nov 2025 19:41:19 -0800
- Archived-at: <https://zsh.org/workers/54088>
- In-reply-to: <CAGdYchsPsgMsT-JtSVizSg5UQZDQbiifO4UQnEP9fjNX_KTkbA@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> <CAH+w=7Z2uwZDovnJzKh1pRfSPSuu5+F-8H+GXmazBe2up4ownQ@mail.gmail.com> <CAGdYchsPsgMsT-JtSVizSg5UQZDQbiifO4UQnEP9fjNX_KTkbA@mail.gmail.com>
On Sun, Nov 16, 2025 at 5:40 PM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>>
>> $r2 is implicitly doing ${(!)r1[2]} because of the "stop at
>> subscripts" behavior. This could at least be documented (note to
>> self).
>
> This looks wrong to me. In my opinion "print $r2" should return the same as "print ${r1[2]}".
Well, yes, that would be ideal ... documentation would be the fallback.
>> 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.
>
> I wouldn't change anything right now. Indeed, if we can eliminate "stop at subscripts", the current behavior might become consistent but if "stop at subscripts" remains in place, your proposal might be the better alternative.
In hindsight it was probably not the best idea to allow the
subscripted references in the first place. I was seduced by symmetry
with ${(P)...} but as with (t), named references are really meant to
be defined on parameters, and as soon as a subscript is introduced the
result has changed from a parameter to a value.
It may be possible to resolve that conundrum in fetchvalue() but I see
no way to do so in getpmparameter() (i.e. $parameters) without
unwanted evaluation side-effects.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author