Zsh Mailing List Archive
Messages sorted by:
Re: [PATCH 1/3]: Add named references
- X-seq: zsh-workers 51394
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 1/3]: Add named references
- Date: Fri, 10 Feb 2023 19:04:56 -0800
- Archived-at: <https://zsh.org/workers/51394>
- In-reply-to: <CAH+w=7bcqc8SsRxsht0QFyXy=DYzj6nVaBFhdzQ5MrBB+yBz+A@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAH+w=7bd5tHQ8_ZFuyheUrTStm8pR826jH1LB-vMdEnv14nH0w@mail.gmail.com> <67689-1675827940.088548@BxvG.D9_b.7RzI> <CAH+w=7ZFq_MyNtPVetDt84Zp8dnCQXis3p=2sKP018GZ-VTd0g@mail.gmail.com> <12608-1675903622.800470@Xj82.e3y1.svhG> <CAH+w=7ZZUCqYe6w1ZqZZKR6iLsZH0SDDXyzwgTU93nxx6bmxjQ@mail.gmail.com> <66045-1675975796.128039@FBF_.0yMO.Y8fk> <CAH+w=7bcqc8SsRxsht0QFyXy=DYzj6nVaBFhdzQ5MrBB+yBz+A@mail.gmail.com>
Closing in on this, I think ... remaining decisions on which input
would be appreciated:
On Thu, Feb 9, 2023 at 3:07 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > Ksh prints "global reference cannot refer to local variable".
> At what point does that happen? Upon the assignment ref=var ?
At the moment, just toying with this, I have it erroring when
EMULATE_KSH, printing a warning when WARN_NESTED_VAR, and otherwise
silently creating the down-scope reference. Thoughts? Perhaps
WARN_CREATE_GLOBAL would actually be better here, or maybe check for
> Relatedly, what should happen on any failed assignment? E.g.
> typeset -n xy yx
> xy=yx # OK so far
> yx=xy # Oops, invalid loop
> Should yx become unset, or should it remain a nameref with no referent?
This probably doesn't matter except at the command line as the
referent loop is otherwise fatal.
> > When relying only on dynamic scoping, it would be good practice to
> > define all the namerefs to passed parameters as early as possible in a
> > function to reduce the risk of a name clash.
> If you were going to put that in the doc, where would it go?
- under Named References in Parameters
- at the description of -n under typeset
- with the scoping example in Expansion
- in a new section under Functions
> > > validate_refname() is calling parse_subscript() ... would further
> > > examination of the accepted string be sufficient, or something more
> > > needed?
> [...] I meant, would examining the subscript string in the C code be sufficient.
> > It might deprive us of many clever tricks but parse_subscript() could
> > gain a flag to disable anything questionable like command substitution
> > and math evaluation side-effects.
parse_subscript() is already a bit of a hack, it sets up its own
context and invokes the lexer. A flag such as that would, I think,
require plugging in an alternate lexer, hence my question about doing
a simpler examination of the string.
Messages sorted by: