From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27786 invoked by alias); 17 Jan 2013 05:00:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30981 Received: (qmail 15659 invoked from network); 17 Jan 2013 05:00:19 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130116210008.ZM22370@torch.brasslantern.com> Date: Wed, 16 Jan 2013 21:00:08 -0800 In-reply-to: <87mwwbfw7q.fsf@lwm.klanderman.net> Comments: In reply to Greg Klanderman "Re: array prepend" (Jan 14, 1:36pm) References: <50EFB80D.30002@sergio.spb.ru> <22417.1357954693@thecus.kiddle.eu> <20130113185141.4394d532@pws-pc.ntlworld.com> <130113175023.ZM5855@torch.brasslantern.com> <87mwwbfw7q.fsf@lwm.klanderman.net> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: array prepend MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jan 14, 1:36pm, Greg Klanderman wrote: } Subject: Re: array prepend } } > VAR[]=(this is prepended) } } So that's the same as VAR[1,0]=(...) ? Well, no, because VAR[] would work regardless of KSH_ARRAYS. But I confess I'd forgotten about reversing the indices like that. For those in the audience, Greg has just reminded me that you can in fact "splice to the left" by using indices in decreasing order; and for zsh-mode arrays there is an empty slot at zero, which you can't reference by itself, but which is allowed in a range expression. So in those circumstances VAR[1,0]=(this is prepended) } It doesn't really "look" very much like prepend to me. I chose it to "look like" splicing something into an "empty" index. If we pretend there's an empty index at each end of the array, ... } > VAR[]+=(this is appended) } > VAR+=(short for 'VAR[]+=') } } Does VAR+=($x) differ at all from VAR+=$x if VAR is an array? Only when $x substitutes more than one word. } I was thinking of maybe '++=' for prepend, the double '+' weighting } towards the front. That would be OK as well. However, it occurs to me that we could allow VAR[] to work for associative arrays; a special case in which you *are* permitted to set a so-called slice, because there's nothing to replace and no order required.