zsh-users
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: sergio <mailbox@sergio.spb.ru>
Cc: zsh-users@zsh.org
Subject: Re: array prepend
Date: Sat, 12 Jan 2013 02:38:13 +0100	[thread overview]
Message-ID: <22417.1357954693@thecus.kiddle.eu> (raw)
In-Reply-To: <50EFB80D.30002@sergio.spb.ru>

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


  reply	other threads:[~2013-01-12  1:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-11  6:58 sergio
2013-01-12  1:38 ` Oliver Kiddle [this message]
2013-01-13 18:51   ` Peter Stephenson
2013-01-14  4:48     ` rahul
2013-01-14 15:32       ` Bart Schaefer
2013-01-14 18:48         ` rahul
2013-01-17  4:34           ` Bart Schaefer

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=22417.1357954693@thecus.kiddle.eu \
    --to=okiddle@yahoo.co.uk \
    --cc=mailbox@sergio.spb.ru \
    --cc=zsh-users@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).