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

Re: array prepend



Bart wrote:
> Hrm, I'm not exactly excited by that choice, /= implies some sort of
> division rather than union.

I was thinking of ^= (given the meaning of ^ in a regex) but that also
implies a mathematical operation. Also note that the current += does do
addition given integer variables much as i=foo is also sensitive to an
existing integer i variable.

> Thinking again, I'm not sure that's the reason.  There doesn't seem to
> be any syntactic reason to exclude -= (it doesn't parse now); rather,
> =+ doesn't work because a + character is valid in the parameter value,
> but I think -= was rejected on the same implied-semantics grounds that
> I just raised for /=.

You're right, with -= it looks for a matching command name. Digging back
in the mail archives it seems I've remembered the reasons wrongly.

> What about a special case for empty brackets?  VAR[] is not currently
> a valid identifier even though e.g. VAR[*] is.
> 
>  	VAR[]=(this is prepended)
>  	VAR[]+=(this is appended)
>  	VAR+=(short for 'VAR[]+=')

That seems reasonably logical. Would the following be possible to prepend
to an array element?
  VAR[1][]="first"

Oliver



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