Array Slice Ranges

renox renosky at free.fr
Fri Nov 10 11:32:15 PST 2006


Walter Bright wrote:
> %u wrote:
> 
>> I'm learning ruby right now, and I noticed they use a very cool syntax 
>> for ranges.
>>
>> 0..5 means 0, 1, 2, 3, 4, 5
>> 0...5 means 0, 1, 2, 3, 4
>>
>> The current array slicing is useful half the time and a pain in the 
>> arse the
>> other half, so I was wondering if anyone else has mentioned this idea 
>> for D
>> before...
> 
> 
> I have a bit of a problem with .. vs ..., I think they both look too 
> similar  making it hard to review code for correctness, and I'd have a 
> hard time remembering which means which, another source of bugs.

When I tried to solve the problem, the best I could come up with was
[0..5] 0,1,2,3,4,5
[0..5<] 0,1,2,3,4
[>0..5] 1,2,3,4,5
[>0..5<] 1,2,3,4

I feel that [> and <] are reasonnably intuitive operators.

But it change D's default so I suppose that this isn't possible as this 
means that D[0..length] would have to be replaced by D[0..length<] or 
introducing a new keyword D[0..last] 'last' being length-1 of course, 
the index of the last element of the array.

Regards,
RenoX



More information about the Digitalmars-d mailing list