From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25169 invoked from network); 18 Jun 2021 10:53:54 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Jun 2021 10:53:54 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1624013634; b=QisJ6glXAomkCcZQRFt8GyR7JcsY2MmOa0YPEyHtL1y0Vxh/CqTKbrTfbioiQxLVuDGrx6H1Py JuXuENkgBvJ2DGiLFRweJxrBrnVzuEfKNlwG1grSFI+LSCg3L7nL/DObskrreU80urEdZ+QbX7 G52XeSs7pmWDMALbl64jVvan1hfQdNQqrhR2dTed/9nBzW9n3km8iZ61tqCUbSRSL9qNf0hSfu xw2htzCbsqqkqI7RIZ96U2D4U82EHt7uhOg0o6Jo6f7BsYXDOnVHLFLxt87wKsBUFuFwKbpLUO PBszPstXzBeo2iTwxK+lVWUafIl3bz8IOdM9B60RXfx27A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1624013634; bh=JslZHU9S4pvNVwaBYPYpWcjt9GW4+kfF9E+hqoXtW3g=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:References: In-Reply-To:MIME-Version:DKIM-Signature:DKIM-Signature; b=lCJ/aGoW2pim0piJ7Xra8XqOd08qcv0qzj0YA3+mUSfyHz9nUzlJK4iXHJkIiEy2eJgGcYw8r5 mavo1NAZw/l3zGDdGeOO1J2u5Ug9DJQHzuIcn25tDhfonGDFb0Bd14zyERGDpDFi8nxPOtsl2I 8UchDAV12M+g7IerIQsVlJFf2PekbS1Fw8uP9PIXQ3DsETFzKv1gUvXTHfdZolIVYsDq9Car5R y0QWIeMFFadKZPvIOpaOT82sAg/7h+G/jUXvCI/tVbhczBZcIDZarQu56pMbjSvjYV+1SYFkCQ Qx622llWTZw/xH3/AibQIWeyav1bzRwNObXXjWR8g6pUyw==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:References:In-Reply-To:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=9kUMaZQseafl0lejeaNxzTYQiLIYTEnUUBY34I+dzS8=; b=ofb7bIe7nV3E6+mz2rHXx5yC0f LReqbsIOohwKdTk6OYbSU3EM48GE0xIuK59pEo1Q7r3n3mdydBBvlkiaeRbQh11bE2lsyr9lIsFru u+J51q5bMMxFMmt6njiJ+XyLLFhhksVAPYhw6f2i13+IZRK6Vw0VvSd+P5MX5ljL1ohr9Beq/hOxr IKhcjraDtWg2uO3OXv6G0NYBEAM5OIC9lUlzScaxbkcpT2NIrrnI+9TttrqvvjBbXbf8xCugn6MOT v4OOceCLsKqe027450krrlc+fCJ2QS18rM/vP+wILsn/FeEG+yJ6+h8slJoyHH8hK80gWWccO4pcU SLDiE7hQ==; Received: from authenticated user by zero.zsh.org with local id 1luC8D-0007mz-Cb; Fri, 18 Jun 2021 10:53:49 +0000 Authentication-Results: zsh.org; iprev=pass (mail-io1-f54.google.com) smtp.remote-ip=209.85.166.54; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-io1-f54.google.com ([209.85.166.54]:39703) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1luC7e-0007TJ-9w; Fri, 18 Jun 2021 10:53:15 +0000 Received: by mail-io1-f54.google.com with SMTP id f10so885038iok.6 for ; Fri, 18 Jun 2021 03:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=9kUMaZQseafl0lejeaNxzTYQiLIYTEnUUBY34I+dzS8=; b=VvZUn1cZryVXCJYxmUkm755fkrEwtKomkbfwmdWKmlW08RfC7n+gfJCXPxBVMSLqyk qrVOfRSWTZ8tksvCkORurnzJG9JixghfqJJuVeVhpU365BW86DxUSRcTbpowCSs/ptmB 5DIDSG8wFKTW6XSrzpnrEzVLDfVs60xFOewuxDbBUg9QTMTMg8zF/JO4CJzYwK6dW0qd iBmrhubeXDPn4rIkxrI3vo18kCB0l07jsutVa/zCppd9uOeDdyvCW4KGbCdS4UqjwPqp CjYbBQOeIQ6YG4Bhv64CXkslBNhLh6Yp9A0VUp0vXY6eAgVjT7sifubTWuwpI7E8D07G fTpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=9kUMaZQseafl0lejeaNxzTYQiLIYTEnUUBY34I+dzS8=; b=CNkuz+Ox9tCjTlQsfAX03p5dzQQ+Nh5WW4Kcg9RgO0jHJcxEGhjspqwngWVMlbwbVV OiLIzXnKPS8X2OV08gUsyW8dSh+08AUW3vP+rPxYpHB6EYCeTUSKuVYsuuQlgW2K3p5Z z/JKqigv1i24yLGpj0ArySRde5EObEHJATeIML7tQarvZ1ElQbGGfaeGhpySnb7NBcvE H2ZVMw3QPaxBssYEDg9YSQhR4/RLaHSCC0CW15nYrx8id2ZO1tkDA7dr+i34X5Pog2Ey XN+UQ2G4U8w0PHkW7aV3KDPlrM/v3/vxgHnb7KmLNQfrpYfvl7gaEPrxCjPx6Prg+x3n 8Mig== X-Gm-Message-State: AOAM531NE/RJDX7TO3ZEWaF6p0oGwJ9RMzycdCxsQPu5xJ0Ql7b+niYB oHWXoChnyLiKPq6j6pZZRogvGL1WBMQMCp1ajvteTMB+ X-Google-Smtp-Source: ABdhPJwcioBv/HVG5HfQavEMXF6RJED8ZETDRj9w1Ja0C2ob5IXZq3J6eUFVG+HAINl7r29GA6PRoCQQf7FAzsGzfNY= X-Received: by 2002:a05:6638:1919:: with SMTP id p25mr2768594jal.115.1624013593077; Fri, 18 Jun 2021 03:53:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a05:6622:2186:0:0:0:0 with HTTP; Fri, 18 Jun 2021 03:53:12 -0700 (PDT) In-Reply-To: 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> <20210505114521.bemoiekpophssbug@chazelas.org> From: Mikael Magnusson Date: Fri, 18 Jun 2021 12:53:12 +0200 Message-ID: Subject: Re: [PATCH] (?) typeset array[position=index]=value To: Bart Schaefer Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49083 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On 6/5/21, Bart Schaefer wrote: > On Fri, Jun 4, 2021 at 9:29 PM Mikael Magnusson 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