RFC on range design for D2
Sergey Gromov
snake.scaly at gmail.com
Wed Sep 10 09:42:54 PDT 2008
Leandro Lucarella <llucax at gmail.com> wrote:
> Andrei Alexandrescu, el 9 de septiembre a las 18:13 me escribiste:
> > "Shrink the range from the left end"
> > "Shrink the range from the right end"
> >
> > The first will be used much more often than the second.
>
> shrink(int n = 1)?
> if n > 0, shrinks from the begining, if n < 0, shrinks if shrinks from the
> end (0 is no-op). This way you can skip some elements too. Even when it
> could be a little cryptic, I think it plays well with slicing.
>
> Another posibility is shrink(int begin = 1, end = 0), to shrink both ends
> at the time, for example (calling shrink1 to the first proposal and
> shrink2 to the second):
> r.pop == r.shrink1(-1) == r.shrink2(0, 1)
> r.pop; r.pop == r.shrink(-2) == r.shrink2(0, 2)
> r.shrink1() == r.shrink2()
> r.shrink1(3) == r.shrink2(3)
> r.shrink1(3); r.shrink1(-2) == r.shrink2(3, 2)
I remember that shift() was a method to remove first element from an
array. Some Basic perhaps... So it could be push, pop, shift, er...
unshift?
But now that I think about it... What's the use case for these
operations? It's clear to me that getNext/putNext are a
generator/constructor pair, in the broad sense. But push/whatever?
Andrei have told already, if I remember correctly, that ranges are views
of data, not manipulators. This means that they cannot be used to
extend a collection. Therefore ranges cannot have any extension methods
whatsoever.
If you draw a parallel between a range and a stack of paper, the shrink
methods would probably be pop/snap... I'd also propose next() for
moving the start and prev() for moving the end. It sounds a bit
misleading but, on the other hand, it closely resembles forward and
backward iteration with the opposite end of a range representing the
iteration limit. Or maybe forward()/backward(), or fwd()/back()?
More information about the Digitalmars-d-announce
mailing list