[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 18:41:25 +0200 |
On 29 Jun 2011, at 15:01, Greg Wooledge wrote:
>
> On Wed, Jun 29, 2011 at 01:42:06PM +0200, Maarten Billemont wrote:
>> 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
Firstly, I see my indenting of the "^ [label]" got whacked off target. Let me
try to correct that, if my MUA allows:
address@hidden:1:2}
values: [ a | b | c ]
indexes: 0 1 2 3
expand: [ 1 2 ] => b c
^ start from 1
^ length 2
address@hidden:1:-2}
values: [ a | b | c ]
indexes: 0 1 2 3
expand: 1 ] [ 2 => a c
^ start from 1
^ length 2
> But if you're starting with element 1, why wouldn't it be "b a"?
This is where preceding the element with the index comes in handy: We start
with the index 1, which lays between element 0 and element 1. We go back 1,
that gives us element 0 and we're now between element 0 and the last element of
the array (assuming a circular view on the array). Go back one more and you
now also get the last element in the array, and the cursor ends up between the
last and the before last element.
For those to whom a cursor between elements seems confusing: think of your
prompt's cursor and imagine an element is a single character. Type this:
abcabc
Put your cursor before the second "a", imagine you're now at index 0:
abc|abc
Index 0 refers to element "a", because when you select 1 character
(address@hidden:0:1}), that'll be "a":
abc[a]bc.
Select 2 elements (address@hidden:0:2}):
abc[ab]c.
Now try going backwards with your cursor to select 2 elements, instead of
forwards (address@hidden:0:-2}):
a[bc]abc
My example was address@hidden:1:-2}, so that would look like this:
ab[ca]bc
- 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, 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}, 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 <=
- 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