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

Re: array prepend



serio  wrote:
> Is there a way for prepend array like += for append,
> or the only possible solution is a = (b $a)?

  a=(b $a)
is the only proper documented way to prepend elements

There are some hacks that do the job such as:
  a[-1-$#a]=(b)
I'm not sure whether I'd rely on that always working in the future,
however.

If you dig out the mailing list discussion from when += was added you'll
see that the main reason there isn't a prepend is that we couldn't think
of suitable syntax that would be backward compatible. -= for example
isn't possible because a - character is valid in an identifier.

Oliver



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