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

Re: Reverse the order of an array?



On Mon, 11 Feb 2002, Oliver Kiddle wrote:

> Allowing array slices to go backwards, is a possibility though I'd not
> be suprised if implementing it caused other things to break.

Right now, using a backwards array slice references an imaginary "empty
element" to the left of the left end of the slice; assigning to that
imaginary element makes it real.  E.g.:

zsh% x=(a b c d e)
zsh% x[4,2]=(y)
zsh% echo $x
a b c y d e

This was motivated by desiring to have a syntax for inserting elements
into the array; "forwards" array slices only allow for replacement.

> The easiest might be a parameter expension flag (r and R are gone so
> we'd need a letter.

We could also use a subscripting flag (though that doesn't help with r/R).

> ^ perhaps as we used that for the reversed prompt state).

No, I don't like that.  ${(^)^x} is just too confusing.

How about if (oa) means "sort in array index order" and (Oa) means "sort
in reverse array index order"?  There's precedent with (oi) and (Oi) for
case-insensitive sorting.  Obviously (oa) is equivalent to the default,
but so what?



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