Array Slice Ranges

Mariano rotoshi at yahoo.com
Fri Nov 10 07:00:31 PST 2006


== Quote from %u (trevorparscal at hotmail.com)'s article
> 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...
> - Trevor

Well, the difference is that in D 0..5 doesn't mean 0,1,2,3,4,5, but
'starting from 0, 5 positions'.

thus, if you want 0,1,2,3,4 you use, well, 0..4.

I know what you mean, though, if you have 1..x you need sometimes to
use 1..x-1, but hey, it doesn't look that bad, and having two
different yet very simillar notations for 'inclusive' and 'exclusive'
sounds like a great srouce of bugs.

Cheers,
Mariano.
Mariano.




More information about the Digitalmars-d mailing list