[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Negative indexes in address@hidden:off:length}
From: |
Maarten Billemont |
Subject: |
Re: Negative indexes in address@hidden:off:length} |
Date: |
Wed, 29 Jun 2011 13:42:06 +0200 |
On 27 Jun 2011, at 16:25, Chet Ramey wrote:
>
>> I don't even understand what the second one is supposed to mean at
>> all -- the :1: means to start with "b" and the -2 means to go back 2
>> elements...? How do you derive "a c" from any possible interpretation
>> of this?
>
> I assume that he wants to be able to treat an indexed array as a circular
> buffer without having to do any of the work in a script.
Exactly, let's draw the array in the example:
arr=(a b c)
values: [ a | b | c ]
indexes: 0 1 2 3
If you expand address@hidden:1:2}, you get the following:
values: [ a | b | c ]
indexes: 0 1 2 3
expand: [ 1 2 ] => b c
^ start from 1
^ length 2
I propose we let a negative length iterate backward, so with
address@hidden:1:-2}, you get the following:
values: [ a | b | c ]
indexes: 0 1 2 3
expand: 1 ] [ 2 => a c
^ start from 1
^ length 2
Since ${arr[-1]} already does exactly this, I figure it would merely add to the
syntax' consistency.
- Negative indexes in address@hidden:off:length}, lhunath, 2011/06/25
- Re: Negative indexes in address@hidden:off:length}, Greg Wooledge, 2011/06/27
- Re: Negative indexes in address@hidden:off:length}, Chet Ramey, 2011/06/27
- Re: Negative indexes in address@hidden:off:length}, Steven W. Orr, 2011/06/27
- Re: Negative indexes in address@hidden:off:length},
Maarten Billemont <=
- Re: Negative indexes in address@hidden:off:length}, Maarten Billemont, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Mart Frauenlob, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Maarten Billemont, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Mart Frauenlob, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Greg Wooledge, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Maarten Billemont, 2011/06/29
- Re: Negative indexes in address@hidden:off:length}, Greg Wooledge, 2011/06/30
- Re: Negative indexes in address@hidden:off:length}, Greg Wooledge, 2011/06/30
- Re: Negative indexes in address@hidden:off:length}, Maarten Billemont, 2011/06/30