Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 1/3]: Add named references
- X-seq: zsh-workers 51410
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 1/3]: Add named references
- Date: Sun, 12 Feb 2023 10:02:03 +0100
- Archived-at: <https://zsh.org/workers/51410>
- 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>
On 9 Feb, Bart Schaefer wrote (I've reordered this):
> > This should be an error perhaps:
> >
> > typeset -n ref=arr[1][2]
>
> Why? ${ary[1][2]} isn't an error, it's the 2nd character of the first
> word in $ary.
Sorry, should have been clearer. Applying later subscripts is even
better than an error but the following is not ideal:
% arr=( one two three )
% typeset -n ref=arr[2][1]
% echo $ref
two[1]
% ref=x
% typeset -p arr
typeset -a arr=( one x three )
% echo $ref
x[1]
% typeset -n ref=arr[1]whatever
% echo $ref
onewhatever
> Yeah, I don't like the idea that a called function can arbitrarily
> grab parameters from its caller just by sticking & in front. Caller
> needs to do do something (even if only make "normal" use of dynamic
> scope) to make the parameter "grabbable".
Allowing such things as uplevel statements (Tcl), special syntax, or
introspection modules (Python's inspect), is fairly normal for a
scripting language.
As I've mentioned, we already have the situation where the caller
needs nothing to make a private grabable by a builtin:
private -a var
compadd -O var one two three
And writing wrappers to e.g. compadd is useful.
But I don't think we need to address references to privates in other
scopes at this point before the other patches are even applied. May be
better to consider whether there are other advantages in moving private
to the main shell first as that may ease any implementation.
> > > typeset -n ref
> > > for ref in 'hash[(e)'${(k)^hash[(R)?*]}']'; do ...
> >
> > "just"!?
>
> Hah! Point was that it's do-able without "for"-context-sensitive
> special subscript semantics. I think it would be strange for
I can't think of a sensible way. Was just that it could be useful.
Best long term solution might be to allow arrays of references. Bash
does allow arrays of integers.
> The others would all have to be special-cased individually. What is
> $+ ? Do you mean $- ?
Yes.
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author