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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 20582 invoked from network); 5 Jun 2021 05:49:46 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 5 Jun 2021 05:49:46 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622872186; b=XHAjNCx9uogJyNVLprNsWb7Ij5T1cSAvi7y2pW/C4P7Rps6we72F2QvIBrgGWAi1bSidTCXufS QdVLMKCLRlCoErlO4GfqTf+61FK0xTI1vTkrklRUQAF2rieQ3rxYbfUzXT3XBAQoF9iuSYPqp7 0dnhBRPH/75u6rIDta94VkVfrl04Obj2bFS6fhWYlt51EHt1bp0dV12eyj9fdye41mCrwfOfOy jRQ8kRw/kOfKsRWeMfxhkbDgVS0S54WpSc4vO+U9FFKuLS2q2eJ3WqjRSBPuUWVhBZ36UIHx6L QMbj7d0hNoNWqHOgT3HyhF9ETHXVuDazj38tAWZQth7uMw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f181.google.com) smtp.remote-ip=209.85.167.181; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1622872186; bh=pYBJpYm66Xp8QjjPmrGAYtApbfX+CTEyrQjZqaiPhEQ=; 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:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=JQ10iEKYQDsaTwQs1O2fT51L6mFEEYQPY9sJYakJUZ/06Nc78uLaF3oFT6/ArEROf1b3kgpZm0 WeLkojBoIt+Qoa1oOHwrjYdbLkn7oF1csSuYJmmX5uY5Pv8MubiQ8GjYOhu1Iow3ozi1CrOTXb bKKwSWiADlggiho+g7e/yj59A1lqp0l6Ma+rdMLgA0B1ueXEZRxVPzALO0vlnfIGB84iJ721Hz CX/L4UC1p6z/tygeb7gfq6ERkUwqueKBkb74k1SbrMIQUrsmiPcBKEV6fWVwTuuvGJF31Fddgt Bubkywj1tVofhEyyq+vsG4Gu4kCZPIpxbzEfXR/CqcSPDw==; 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:In-Reply-To:References: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=WyfJE2pQp2ENEj+OPZ0etSJu3x/NEBMBGvOdQJLn7p4=; b=Fh404+WHLE0MXLxHlVxtlVwSpH R6UWVEzCHk5cMqp+BYWSTwAFLowzQrOQKCDIunAcd02BcvzPxXhLt21h+zitrklKrLlxsXmIPX17R IO+jBKqT9TSzzbrPElVDu1Z1oBcuUIt4Sh87U+YLY/vV1XU9LTs28B8xHOjZQrxoEG2Ts9Z0lgHAS KNbep/wMsvtO02v2J/K66Y8KRtyat/tYHGNPlUaoLOXYbjzvr5DOmejQoO70OSGuRqLhYNcr0xiz4 kWDN81EysU+oi9azUEBFRmQdJZwmUNwcQaNJZnXbc4dVKbWTKirmIgzIUE85c1SnXRoH4uukN5Itr 27iHKOag==; Received: from authenticated user by zero.zsh.org with local id 1lpPBp-000Dmn-Sr; Sat, 05 Jun 2021 05:49:45 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f181.google.com) smtp.remote-ip=209.85.167.181; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f181.google.com ([209.85.167.181]:35614) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1lpPBX-000DVF-1y; Sat, 05 Jun 2021 05:49:28 +0000 Received: by mail-oi1-f181.google.com with SMTP id v22so12044628oic.2 for ; Fri, 04 Jun 2021 22:49:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=WyfJE2pQp2ENEj+OPZ0etSJu3x/NEBMBGvOdQJLn7p4=; b=2TMSMSW1+Zoopgh03j25QtCThBN7rRam/o86Qe6hJ5YBSBsM8rFKWIbuZTouQfuTX8 +uk4CvWV4SdpgYn34xSdGBtljQmD+gabJYLCS2y2xTAcW5BWyYYngBW65Pt1UElZBIN7 b/xTEzmZGdoOt12+xkv89nUmOzMeR5mfLVEe4iPEBLpGxKzle1xnydL7hKxxgbnN10Mt iua63A9D+j8ZkHqX6gdCl26JK+hOtE7XgZDctAevin6f6l1YkMQHSDt/iariG4NrXmb5 BSq77g9QMmjwca4bKs3OWk+yYkuxkQuojkuPf7g/qkvi0Z8NWj23UGcGo5siNnV6TyP0 WgkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=WyfJE2pQp2ENEj+OPZ0etSJu3x/NEBMBGvOdQJLn7p4=; b=Nl92DubmSbBpkDhKC5Lw1vOLZSoMBJt0wu8/0lRpU/jtx7AjTrgXmJx7inamsq1Mw9 FUKOG+zSu/y411YYEYyIrewAdRspU+daKvK8SJtGcmHcxkKo3+1I7I2oT4ngpMkA4bgl poq0pKGasWrXqeGVca7vDINkzq3NWJiOclnwq/Aeo4VmF3lyU3rlg84TB/2M+HjI+DVB kSb0WexrMo6MvnEmv7uAmVz0KlbEwRUrDbN0Pqpuhff7zn05WB4NmIv8+aft5eWbwnpl qNKNgbVJr6lfwpgfcweJ9aykNXlmun8EXFE2w0OqQjRd8HABS2WbbHa+i4P7cYgadDrk 876g== X-Gm-Message-State: AOAM531XorFlu+hgYrMaVAQSXG+nXtueJY/y3dWBB0ab3LO08SnxSS87 1RPnHwJf+p6mHtNoePagzqyX2Hi7khX+H1f6EPwqng== X-Google-Smtp-Source: ABdhPJyNdIzBW7wDBlGV/Pyk5MOJ8c9b+mT1+alJWA9zTM5/PF+DMzGUAl7AcUhhViBG/EzcFJbTU1NWtBpT6TlpH2o= X-Received: by 2002:aca:f452:: with SMTP id s79mr3757840oih.84.1622872165434; Fri, 04 Jun 2021 22:49:25 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: From: Bart Schaefer Date: Fri, 4 Jun 2021 22:49:14 -0700 Message-ID: Subject: Re: [PATCH] (?) typeset array[position=index]=value To: Mikael Magnusson Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 49021 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 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? > % 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]=() ) foo[a]=( z ) foo[a]=( x y ) etc. > 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). > and for assoc arrays it is an error. Because you can't perform a splice on a hash table.