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 3927 invoked from network); 2 Jun 2021 16:02:23 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 2 Jun 2021 16:02:23 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1622649743; b=fw1mpmuBTaMXDEsJ3uDH/kLplSx+aAEIJIf7P3sJ7BJINCR5nVyJ/mQ0/jnLw5xd03wNtNIIOr 0a+eNLQeAIk81Z4iuUoV6hRFf0CJ9SB6u3+fD61yYlSyY7BQ+lfuqR89Ev/4wTirBsJH6MMtIX bqEeeO7yYEKme2RB3bJTpjqQpWLLjECZa5g5BZmLuhlrxCxbaY9Rvu00B4rWMh5ikdGb7QxJyd 0MVP0jJyB7QpDLS1Iat8NF/C7JW9h/2tmSiGwLmziGMvSRGoTeayatLTEmh8Bj4+QGT1+YtUPf UcoKS7VsjUqFle0fqLbsHfhwmfB96sizLaaJnL6Cu7U6rA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1622649743; bh=0kc9DQj9Edg4QHWYXDMg+03l5YQYqutYmNuEqRJVcF0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=ELoceZ/okMr2kKTmHizYpiULEU/o+0zsPVomabg9JL2C2X7CxIcO35zDbqcHXMlMwe6gaIMBCd UW0qK/c9Ett07ulUP0i66YODe9aQiv59wlQ7DVq/PiZSffMUjIZWdhil0ThG7PUf19jhLJR+oX qqYS9ODbyt4JzC9Io765WvVQ/Os8LbjJcfql3rNsyEuPddLhE57zLqmkMHtRinIl+fSiM5mo1n GbrbooAQaL8glTSITsTqPLqpdc/LQqoVQipzQ3KS1JddZlVaYhKcRCiotBlGc5klskT5Jn6Mdo vrXz1wc/45SVDF27npcAm+5knDCt3aLrhxpSaVCmDAyWDA==; 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:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=9+dYjQlv6IPXAMNFOtP0hSQpVMaD5KMuyOMjkWooKuE=; b=ESMsinH2+xPNVksmAzsVQDXcJJ 7re/uUr4curA4E7B2HEfg8T8Q90YPbQ2Nc4JonR2UgNJFhGBJ6JGjlfm878LFDoF8MoU7GtOqzz9P RGvKrbAPt0QxdgE8ZN27ghICy8KuB8/M2OA4a5B24NZ1n3YDShvzxZwhEq0JniGC3VCk8G31Wd1Pe DDkiUXXqXxk8dJXtCrDEppvPZzck4SCWbv409k4JoPxM86HI+SU816K7HYnYQDeYuJfgdmjMztQ/m zyUG+07VjIRmA1EjF3qN263aIVp3302FoYc2wI/SmXBG7Yurm3znIy1Zn8H5fP5lYuxhGOCj+KsMy HcpijwqA==; Received: from authenticated user by zero.zsh.org with local id 1loTK2-000MC3-UX; Wed, 02 Jun 2021 16:02:22 +0000 Authentication-Results: zsh.org; iprev=pass (relay9-d.mail.gandi.net) smtp.remote-ip=217.70.183.199; dmarc=none header.from=chazelas.org; arc=none Received: from relay9-d.mail.gandi.net ([217.70.183.199]:47549) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1loTJo-000Ltv-F6; Wed, 02 Jun 2021 16:02:08 +0000 Received: (Authenticated sender: stephane@chazelas.org) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 91251FF81B; Wed, 2 Jun 2021 16:02:06 +0000 (UTC) Date: Wed, 2 Jun 2021 17:02:06 +0100 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [PATCH] (take two?) typeset array[position=index]=value / unset hash[$stuff] Message-ID: <20210602160206.jhfp4lvua2hvub7c@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20210430061117.buyhdhky5crqjrf2@chazelas.org> <20210505114521.bemoiekpophssbug@chazelas.org> <20210601053235.b4junj6muuwegl7b@chazelas.org> <20210602100651.qn3rrop5dup46ikc@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 48989 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: 2021-06-02 07:52:25 -0700, Bart Schaefer: [...] > > I have to admit I don't see the problem here. I would have > > thought allowing a[]=foo and unset 'a[]' would be no-brainers > > Mostly I was thinking about > > key=$(some derived value) > unset "hash[$key]" > > In existing code that would fail on [[ -z $key ]], but you can't see > that by examination. Not sure I follow. That script doesn't work properly atm as it fails to unset the corresponding hash element and would be fixed once we allow unset 'hash[]' I can't think of real life scenarios where one would *rely* on unset 'hash[]' Aborting the shell with a zsh:unset:1: hash[]: invalid parameter name error. > > as there's no concern about backward compatibility as those > > currently return an error. > > That's not our usual criteria for backward compatibility. Usually we > only change things if the new construct was previously a syntax error, > something that would prevent an old script from even being properly > parsed. By that logic, we could never add features like new options to builtins or new flags. For instance, we couldn't add a -k option to unset because unset -k key arr currently is not a zsh syntax error, that script is parsed OK, and that command returns with: unset: bad option: -k [...] > > Even for plain arrays, IMO, it would make sense to allow empty > > subscripts. In most contexts, an empty arithmetic expression is > > interpreted as 0: > > But ... there's no such thing as array position 0 in native zsh. But it would make the API more consistent if array subscripts could be any arithmetic expressions or comma-separated pair of arithmetic expressions. And when ksharrays is not enabled a[] to return the same error as for a[0] or a[empty] ("assignment to invalid subscript range"). Note that 0 position is allowed in second place: a[2,0]=x for instance (or a[2,empty]=x, but not a[2,]=x atm) to insert a x in second position. I'm not saying that's something we should do or would be terribly useful, just that it would make the interface more consistent, and that array[] being rejected should not be a justification for rejecting assoc[]. [...] > > The fact that (e) is recognised and (ee) is > > not also makes for a not very consistent API. > > What would (ee) mean? The e flag passed twice. echo $a[(e)*], $a[(ee)*], $a[(eee)*] All expand to element of key "*". -- Stephane