Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] (?) typeset array[position=index]=value
- X-seq: zsh-workers 49020
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: [PATCH] (?) typeset array[position=index]=value
- Date: Sat, 5 Jun 2021 06:29:06 +0200
- Archived-at: <https://zsh.org/workers/49020>
- In-reply-to: <CAH+w=7bVn2LiTsq194GjshVSOCSib7t4T=uZQ2ZvUGu6Z2XoPw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <20191216211013.6opkv5sy4wvp3yn2@chaz.gmail.com> <20191216212706.i3xvf6hn5h3jwkjh@chaz.gmail.com> <20191217073846.4usg2hnsk66bhqvl@chaz.gmail.com> <20191217111113.z242f4g6sx7xdwru@chaz.gmail.com> <2ea6feb3-a686-4d83-ab27-6a582424487c@www.fastmail.com> <20200101140343.qwfx2xaojumuds3d@chaz.gmail.com> <20210430061117.buyhdhky5crqjrf2@chazelas.org> <CAH+w=7bHxSbFr60ZU0+oZ6+qEejhfBYTzvL7=aXadY5XzWtSzw@mail.gmail.com> <20210505114521.bemoiekpophssbug@chazelas.org> <CAH+w=7ZqE2DnxpHhvCjZnXB4A1vJ=EKB2fpWyUMaZX0VYqU9kg@mail.gmail.com> <CAH+w=7bVn2LiTsq194GjshVSOCSib7t4T=uZQ2ZvUGu6Z2XoPw@mail.gmail.com>
On 5/31/21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Mon, May 31, 2021 at 11:18 AM Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>
>> On Wed, May 5, 2021 at 4:45 AM Stephane Chazelas <stephane@xxxxxxxxxxxx>
>> wrote:
>> > [typeset] chokes on lvalue='array[n=1]' or
>> > lvalue='assoc[keywith=characters]'
>>
>> Hmm, I wonder if that should be considered a bug.
>
> This copies (tweaked for context) the code from parse.c at line 2006
> or thereabouts.
>
> All tests still pass, but as you can see from the comment this is not
> yet handling x+=y which there doesn't seem to be any reason for
> typeset NOT to support; I think it would require only another flag in
> struct asgment, but I haven't attempted that.
>
> Commentary?
Is there some fundamental reason we couldn't just make the obvious
thing work instead?
% typeset -A foo
% foo=(a b c d)
% foo[a]=()
# what actually happens
zsh: foo: attempt to set slice of associative array
# what seems reasonable to happen
% typeset -p foo
typeset -A foo=( [c]=d )
Relatedly, this also seems very inconsistent:
% typeset -A foo
% foo=(a b c d)
% bar=(a b c d)
% unset 'foo[a]'
% unset 'bar[2]'
% typeset -p foo bar
typeset -A foo=( [c]=d )
typeset -a bar=( a '' c d )
So for regular arrays, unset will just set the element to the empty
string, for assoc arrays it removes the key and the value.
For regular arrays, assigning () to the element unsets(?) the element,
and for assoc arrays it is an error.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author