From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3508 invoked by alias); 17 Jan 2013 14:52:22 -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: 30983 Received: (qmail 22661 invoked from network); 17 Jan 2013 14:52: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 klanderman.net does not designate permitted sender hosts) From: Greg Klanderman To: zsh-workers@zsh.org Subject: Re: array prepend Reply-to: gak@klanderman.net Date: Thu, 17 Jan 2013 09:52:01 -0500 In-reply-to: <130116210008.ZM22370@torch.brasslantern.com> (Bart Schaefer's message of "Wed, 16 Jan 2013 21:00:08 -0800") Message-id: <87ip6veub2.fsf@lwm.klanderman.net> User-Agent: Gnus/5.1008 (Gnus v5.10.8) XEmacs/21.4.22 (linux) 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> <130116210008.ZM22370@torch.brasslantern.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii >>>>> On January 17, 2013 Bart Schaefer wrote: > } 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. right, though pretty much any script using arrays is going to break if you flip KSH_ARRAYS.. :-) > } 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, ... yeah, I like the '[]' to indicate splicing into an "empty" index, I was thinking VAR[]= vs VAR[]+= don't really clues me in to which is prepend vs append. But thinking about it more, I guess since += already means append, you chose to keep that meaning, so it does make sense to me now. > } Does VAR+=($x) differ at all from VAR+=$x if VAR is an array? > Only when $x substitutes more than one word. Ahh OK, I see when SHWORDSPLIT is on, VAR+=$x does not perform splitting on $x but VAR+=($x) does. > } 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. You lost me there.. you can already use += on associative arrays AFAICT, what does [] give you? How do prepend and append differ, just the precedence when one a new key already has a value in the associative array? Greg