RFC on range design for D2

Leandro Lucarella llucax at gmail.com
Wed Sep 10 07:33:26 PDT 2008


Andrei Alexandrescu, el  9 de septiembre a las 18:13 me escribiste:
> Derek Parnell wrote:
> >On Tue, 09 Sep 2008 10:30:58 -0500, Andrei Alexandrescu wrote:
> >>I'd like to go with:
> >>
> >>r.first
> >>r.last
> >>r.next
> >>r.pop
> >LOL ... I was just thinking to myself ... "what's wrong with First and
> >Last? I should suggest them." then I read this post.
> >"next" is fine, but "pop"? Isn't the pair of "next" called "prev(ious)" and
> >the pair of "pop" called "push". So please, either have next/prev or
> >push/pop, and in that case push/pop looks quite silly.
> 
> Previous is confusing as it suggest I'm moving back where I came from. In 
> reality I shrink the range from the other end. So we need:
> 
> "Shrink the range from the left end"
> "Shrink the range from the right end"

You mean from begining and the end I guess ;)

> 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)


-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
<o_O> parakenotengobarraespaciadora
<o_O> aver
<o_O> estoyarreglandolabarraporkeserompiounapatita


More information about the Digitalmars-d-announce mailing list