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

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



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.

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.



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