From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1916 invoked by alias); 1 Jul 2012 22:23:43 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30555 Received: (qmail 20390 invoked from network); 1 Jul 2012 22:23:40 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120701152310.ZM28640@torch.brasslantern.com> Date: Sun, 01 Jul 2012 15:23:10 -0700 In-reply-to: <20120701191526.50e2cf7d@pws-pc.ntlworld.com> Comments: In reply to Peter Stephenson "Re: PATCH Re: let unset array element remove compatible with bash" (Jul 1, 7:15pm) References: <120221210106.ZM13374@torch.brasslantern.com> <20120222095248.1ea8140b@pwslap01u.europe.root.pri> <120222092827.ZM24425@torch.brasslantern.com> <20120222201939.53899980@pws-pc.ntlworld.com> <120701095354.ZM28458@torch.brasslantern.com> <20120701191526.50e2cf7d@pws-pc.ntlworld.com> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Subject: Re: PATCH Re: let unset array element remove compatible with bash Cc: Daniel Lin MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jul 1, 7:15pm, Peter Stephenson wrote: } Subject: Re: PATCH Re: let unset array element remove compatible with bash } } On Sun, 01 Jul 2012 09:53:54 -0700 } Bart Schaefer wrote: } > So the patch below makes } > } > noglob unset foo[x] } > } > work properly. If x is an existing index (or valid slice), it is cut } > from the array as if by foo[x]=(). } } Do you mean that? That's not how bash works, it doesn't cut the } element, just remove the value at that index I do mean that; this is the closest zsh can get to the bash behavior, I think. Bash represents arrays as linked lists of position-value pairs, so it's possible for it to have an array with a hole, but zsh uses real arrays. It'd be easy enough to tweak the patch to put an empty string into the element instead of splicing the array, but then it'd be inconsistent with bash's expansions of ${foo[@]}, ${#foo[@]}, etc. I suppose we could invent a new metacharacter like Nularg that means the embedded-in-a-string equivalent of PM_UNSET, but that seems a bit beyond the scope of the discussion so far. Or we could change zsh's internal representation of "ordinary" arrays to use hash tables. That might not even be too difficult as we already have code to produce array representations of the keys or values of hashes, we'd just have to impose an ordering. I don't think that's necessary in order to fulfill the spirit of this particular request, though. Daniel Lin cc'd for comment in case he's not subscribed to zsh-workers.