zsh-workers
 help / color / mirror / code / Atom feed
From: Greg Klanderman <gak@klanderman.net>
To: zsh-workers@zsh.org
Subject: Re: array prepend
Date: Thu, 17 Jan 2013 09:52:01 -0500	[thread overview]
Message-ID: <87ip6veub2.fsf@lwm.klanderman.net> (raw)
In-Reply-To: <130116210008.ZM22370@torch.brasslantern.com> (Bart Schaefer's message of "Wed, 16 Jan 2013 21:00:08 -0800")

>>>>> On January 17, 2013 Bart Schaefer <schaefer@brasslantern.com> 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


  reply	other threads:[~2013-01-17 14:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <50EFB80D.30002@sergio.spb.ru>
     [not found] ` <22417.1357954693@thecus.kiddle.eu>
     [not found]   ` <20130113185141.4394d532@pws-pc.ntlworld.com>
2013-01-14  1:50     ` Bart Schaefer
2013-01-14 15:48       ` Oliver Kiddle
2013-01-17  5:02         ` Bart Schaefer
2013-01-14 18:36       ` Greg Klanderman
2013-01-17  5:00         ` Bart Schaefer
2013-01-17 14:52           ` Greg Klanderman [this message]
2013-01-17 15:49             ` Bart Schaefer
2013-01-19  7:53             ` Han Pingtian
2013-01-19 16:41               ` Bart Schaefer
2013-01-20 11:08                 ` Han Pingtian

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ip6veub2.fsf@lwm.klanderman.net \
    --to=gak@klanderman.net \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).