Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH Re: let unset array element remove compatible with bash



On Sun, 1 Jul 2012 15:23:10 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> 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 <schaefer@xxxxxxxxxxxxxxxx> 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.

Hmm... I'd have said putting in an empty element in was the least
surprising thing to do, at least in the short term.  I don't think
shifting an array so that the numbering is different mimics the ability
to have only certain elements set to any great degree, there are too
many other cases.  If we ever did add the ability, the effect would be
to remove elements that currently appear as empty strings --- so having
the array index shifted would then look wrong.

It's a bit hard to give a definitive answer because, with the
current underlying behaviour, neither meaning of unsetting an array
element actually adds the ability to do something you can't already do.

-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK



Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
More information can be found at www.csr.com. Follow CSR on Twitter at http://twitter.com/CSR_PLC and read our blog at www.csr.com/blog



Messages sorted by: Reverse Date, Date, Thread, Author