Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] (?) typeset array[position=index]=value
- X-seq: zsh-workers 49083
- 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: Fri, 18 Jun 2021 12:53:12 +0200
- Archived-at: <https://zsh.org/workers/49083>
- In-reply-to: <CAH+w=7aVdHRYCnpXdO6E+FwMoM5jvVvD+1am70k76ca8q5-WyQ@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> <CAHYJk3RSDVjxAPhz5Z+1D31-tZtL5qFonokPY=tTauK8RzAXew@mail.gmail.com> <CAH+w=7aVdHRYCnpXdO6E+FwMoM5jvVvD+1am70k76ca8q5-WyQ@mail.gmail.com>
On 6/5/21, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Fri, Jun 4, 2021 at 9:29 PM Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> Relatedly, this also seems very inconsistent:
> [...]
>> So for regular arrays, unset will just set the element to the empty
>> string, for assoc arrays it removes the key and the value.
>
> That's because zsh doesn't support sparse arrays, and the NULL element
> indicates the end of the array, so you can't put a NULL element in the
> middle. If we'd thought about it long ago, it might be an error to
> unset a regular array element, but we're stuck now.
>
>> For regular arrays, assigning () to the element unsets(?) the element
>
> No. For regular arrays assigning an array to an element splices the
> rvalue array into the lvalue array. Splicing the empty array
> shortens the regular array, it doesn't cause elements to become unset
> (unless you consider that the former $#'th element is now unset
> because that position no longer exists).
I just happened to come across the following, and I'm struggling to
fit the result into any sort of logic:
% a=( {1..50} )
% unset 'a[5,45]'
% typeset -p a
typeset -a a=( 1 2 3 4 '' 46 47 48 49 50 )
So did we just remove the given elements, or set them to the empty
string? Yes, we did both :).
(note, this isn't intended as an argument for or against any previous
points, i'm just mentioning it because it still seems inconsistent to
me)
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author