Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 1/3]: Add named references
- X-seq: zsh-workers 51415
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 1/3]: Add named references
- Date: Sun, 12 Feb 2023 10:59:22 -0800
- Archived-at: <https://zsh.org/workers/51415>
- In-reply-to: <94092-1676192523.865597@yGHQ.rexg.4E4Z>
- 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> <94092-1676192523.865597@yGHQ.rexg.4E4Z>
On Sun, Feb 12, 2023 at 1:02 AM Oliver Kiddle <opk@xxxxxxx> wrote:
>
> % typeset -n ref=arr[1]whatever
> % echo $ref
> onewhatever
Aha. OK, that's pretty easy to fix.
> 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.
I think it would in fact be necessary to move private to the main
shell in order to fix this. The second-worst hack in private is the
overloading of some parameter flags, and the internals of e.g.
createparam() et al. need to be able to distinguish the cases of the
original flag meaning from its overloaded meaning. Builtins have the
advantage of not passing through that code path.
> > > > typeset -n ref
> > > > for ref in 'hash[(e)'${(k)^hash[(R)?*]}']'; do ...
>
> I can't think of a sensible way. Was just that it could be useful.
What about adding ${(K)array) to return array[1] array[2] ... ?
for ref in ${(K)hash}; do ...
I took a quick look at the implementation of (k) and (v) and (K) looks
do-able with sufficient messing around in paramsubst(). Which I'm not
feeling like undertaking myself just now, though.
> Best long term solution might be to allow arrays of references. Bash
> does allow arrays of integers.
Bash also has sparse arrays, its implementation is quite different.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author