[Submission] D Slices
eles
eles at eles.com
Tue May 31 09:21:58 PDT 2011
> Is Python successful?
> >>> a = [0,1,2,3,4,5,6]
> >>> a[3:5]
> [3, 4]
Well, I am not a Python user, I give you credit for that. Actually, I
don't really appreciate Python for its indentation choice, but that's
a matter of taste.
> In C++'s iterator concept, x.end() points to one position after the
last
> element, so the a "range" (x.begin(), x.end()) is has an open limit
at
> the end. Every C++ algorithm that operates on a pair of iterator
take
> use [...) range concept.
That's a good point. I work in C, not in C++. I think it comes from:
for(i=0; i<N; i++){}
while other languages use more
for(i=0; i<=N-1; i++){}
> BTW, Ruby has both of them
> >> a = [0,1,2,3,4,5,6]
> => [0, 1, 2, 3, 4, 5, 6]
> >> a[3..5]
> => [3, 4, 5]
> >> a[3...5]
> => [3, 4]
So, they have studied the well established ground of using an open-
right limit and... chose to implement the other way too. Good for
them. But, if using right-open limit is the natural and established
way... why then, the choice they made?
More information about the Digitalmars-d
mailing list