Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH 1/3]: Add named references
- X-seq: zsh-workers 51386
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH 1/3]: Add named references
- Date: Thu, 09 Feb 2023 03:01:00 +0100
- Archived-at: <https://zsh.org/workers/51386>
- In-reply-to: <12608-1675903622.800470@Xj82.e3y1.svhG>
- 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>
This isn't a self-reference because the local levels would be different.
And "self reference" in the error message should be hyphenated.
typeset -n ref=var
foo() { typeset -n var=ref }
foo
foo:typeset:1: var: invalid self reference
With -g it would be, however.
I wrote:
> On the subject references to array elements, it does seem both powerful and
> dangerous that subscripts are evaluated on reference. The subscript
This is fairly sane:
typeset -n ref1=arr[ref2]
typeset -n ref2=ref1
echo $ref1
zsh: math recursion limit exceeded: ref2
This seems useful:
arr=()
typeset -n ref=arr[1,0]
ref=4
ref=5
Similar:
idx=1
typeset -n ref=arr[idx++]
echo $ref $ref
This is where I worry about security:
arr=( 1 2 3 4)
typeset -n ref='arr[$(echo 4)]'
echo $ref
typeset -p ref # it was only evaluated late thanks to quotes
Maybe the code should have a safer mode for subscript evaluation. This
could be useful but it is asking for trouble.
Also can see this being useful:
str='one two three'
typeset -n ref=str[(w)2]
ref=zwei
We already talked about this error message. But now it is a substring.
export ref
export: ref: can't change type of a named reference
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author