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 23330 invoked from network); 5 Jun 2021 11:06:18 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2021 11:06:18 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622891178; b=Ttm6xQBiWP7Y1ukdYghaEEdjwA5R/QtQ8Mx3n43QMnbjN1k5BJSNnlw2akVxfFMJz+pwrcPQAj rek4ZpzQBIqGXoTYsPJye1R6u2NjgPlkxcaIij1AviuQZp25iyAbqIWQFdF7iQnQHin2a30MRQ GJjSu3T9384nQ0Ibcx2MLZA51sGyHPOGWBH3PTwcpPesqPmuI/rFoQCOXji0bCdtJGzf8RW0vJ vB+pInahNURz3YPtV/+umbYhvk7lhOAaHwv81rwEstXlXddbyiO6DoLi0m6PXwGd2X/6k37OSl lN0nwv/K66/FUZBmnAi0ZwiwjTYWb+mntY4STEA2loVS+w==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-io1-f44.google.com) smtp.remote-ip=209.85.166.44; 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=1622891178; bh=V1sf20lDe6fHTnROIhQ5PX6Vo32hcJdNYn2I/wL7lss=; 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=TxsAg1oH37AOvALQRV90MlIi6vordvTRChodmb82m6e8QjvzU8w6GAwuWUSMWLX1ti1hIoaFNY MsFo4DZTY1oaezNE8ujqqMrQujxu0qBFa3QhmcZBJXiN9NEn+Xgm15JR/KJRDrqasDLU+HrewI dukBDuwc5dVTXikp4a4AcNpD5xOYGeqKGYgh4CkMinqWy+0FXfWOba88eiD61PZksbjH9TFSI3 VkZxF74vDmkjDoH+zHFnD8bqNVEViVNOv6y/Pwi9KJiPkAOQP0DGpdWWCWUzwGVvP5RqVfj7Xj 02eweHLbwhgdD2j4vU2Q1HD7cEgjMH90/9OrfjC51jPYuQ==; 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=s/vk0rbfLWqCbv0bvljnJwW8fpFCFDwi96V7jwLMK4k=; b=ZiBq/Nm8V6hAxWrCUpU3jwDaV9 t5TVxWLe/mvd+5Ej0F4dN3PbnUo/BQ1Gx4UiKQiZbJv97tfoSSy4ALtf0kxDFKd/WV/Ph/TWAytCf yTJarHcb1xwXuUzSTcM24yQm7yAY6W7QN6SWavbP8OS3xALl124xOrIYCJHiogA08hJARGzy/bQQd k9UiMD/bFAXXjSOv++FL85SHyyOthugg/oRZOrt5VvmGCmO4GHsXh7im8l7PTZvZ8kmBoEfabtZ7g kiIUkik0VOruhsMwUO5PCq7SdQlN/HmKj9N30+MPqdZ+4wrQ0d/AMwUiV9y1Sw0CSDncYsu9/3xI5 M7OiOU1A==; Received: from authenticated user by zero.zsh.org with local id 1lpU8A-0002Mp-D8; Sat, 05 Jun 2021 11:06:18 +0000 Authentication-Results: zsh.org; iprev=pass (mail-io1-f44.google.com) smtp.remote-ip=209.85.166.44; 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-f44.google.com ([209.85.166.44]:36570) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lpU7y-00026Z-1K; Sat, 05 Jun 2021 11:06:07 +0000 Received: by mail-io1-f44.google.com with SMTP id s19so3222762ioc.3 for ; Sat, 05 Jun 2021 04:06:05 -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=s/vk0rbfLWqCbv0bvljnJwW8fpFCFDwi96V7jwLMK4k=; b=NgZ2v7xM52DmxESQlLoMUzxS6Skwd8hO95liTkT7N/Y2XFVTLvDEgRSkYO9gl82gXl PWmjqCcf6UL0975TXBDBJU0xQxudYwzbfwnhMDlQ+lGt0QYX2J2FZQDY9S5hf72FRF+E 92NxCaCbHr46mQpFVmSIEAKZTPCd5vkHlw8MdDdKS2qI4q1BvxE3T0NYmKMtOPd3pZxC ucHFEatiqsijDnmXRtrD39dF6abrNe9kjetpk4P31zXw68+Wl7bBXc2BVRBdsi3UNiyl 3lUc/8MPpxi6Hj/0Z/UvFoLFHNUfQHY+Zv6OxCJEauf+6kpXnTTM9DXmepSFk6YzAQiK YBUA== 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=s/vk0rbfLWqCbv0bvljnJwW8fpFCFDwi96V7jwLMK4k=; b=jPsK+2jg881ZuhSca8NE75YFLCvAK+BDGUwHAbtKZZaOJguimRIm+AdZqgOxqBoixl XtbeLHcz763VKV91J5OFxkAdB9Z57XqdhW8T/269zRTBQX/AoGFJxK8nNnHcLybu7gFl hdUJ3IoMe8yLFUmUIOLICOjkw3esXQll6EJ6ocMxU9i/cHG+s6O3Z4Nqjvq+QIvSkikw hBsA0l1o8VXyo6LTV++lt+YLPe2tk3mi40PMsy/aUi4LPeyIKZs2aZpBckJFRfwSnQOR yJqcGH8wGivjDFCeokvyCtv+q9qugoPqujHEywxbbxTGpXeeEd0BBHZuPm8eaYLluwx3 euaQ== X-Gm-Message-State: AOAM530Zd2hBoJ0d5+1Io+nF8p6ZUOTTAbJtltx66qVUZwR7YK96SVxs b5kjAzZA3SHfN25dPzwC+D77V4U+vxx6W1uikL8drzwe X-Google-Smtp-Source: ABdhPJxFWSt5hKBNnu9O5fjyFCdxOwSC2MsTCKBmyBqXBPMLPItgpedrGC5y6It+XvN4ds9d+tf/ApdGnRXzGWuZ4W8= X-Received: by 2002:a6b:7b0a:: with SMTP id l10mr7376831iop.120.1622891164816; Sat, 05 Jun 2021 04:06:04 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a4f:e1da:0:0:0:0:0 with HTTP; Sat, 5 Jun 2021 04:06:03 -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: Sat, 5 Jun 2021 13:06:03 +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: 49023 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: >> >> On 5/31/21, Bart Schaefer wrote: >> > 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? > > For one thing, because the above isn't about what happens to the > value, it's about whether assignment can understand the key? Well, there was 4 different threads about saying "unset foo[$bar]" and I didn't know exactly where to reply so I went to the source, maybe I went one thread too far back though. >> % 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 ) > > The problem is with the follow-up questions, namely ,what should happen > with > > foo=( [a]=() ) remove foo[a] > foo[a]=( z ) set foo[a] to z > foo[a]=( x y ) error > etc. there probably aren't more cases >> 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). By this logic, unset "foo[bar]" should have had the same effect as foo[bar]="" (also too late). >> and for assoc arrays it is an error. > > Because you can't perform a splice on a hash table. Well, with my naive end user hat, this seems much more logical to remove an element than fiddling with the unset keyword, which doesn't even do the same on a normal array. If you come from knowing that bar[5]=() removes the 5th element, then it's reasonable to assume that foo[baz]=() would work too. Since we've established that both unset and assignment to an element behaves in no way the same already for regular arrays and associative arrays, is there any reason to not make assignment to associative array slices (with the empty slice) just remove the element? The parsing already works and it wouldn't break any existing cases. -- Mikael Magnusson