Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: array prepend
- X-seq: zsh-users 17554
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: sergio <mailbox@xxxxxxxxxxxxx>
- Subject: Re: array prepend
- Date: Sat, 12 Jan 2013 02:38:13 +0100
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s1024; t=1357954694; bh=BZiZ0mCtmkSQltRNl+wsqeqcQUFz5yygWSzLopH/NPs=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Received:cc:In-reply-to:From:References:To:Subject:MIME-Version:Content-Type:Content-ID:Date:Message-ID; b=4HVjilvxnDi4tQVwKH5Ck5nt1H+UlYRmw5nfYgJjyWLvzNvBWkcQzNAvt6apiRhX0OeoAwLwpUfKzVOcPfjkMn4a9dcQDI3Lw0Jewtvp18McRy1SSDMysnvolN8fIU46XTbU13dGgUs9JqGuaPCVevSOlkCdUb5LSo3h39LzbpE=
- In-reply-to: <50EFB80D.30002@sergio.spb.ru>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author