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

Re: [PATCH 1/3]: Add named references



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
either one.

> 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?

Options are:
- 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: Reverse Date, Date, Thread, Author