Jan-Willem Maessen | 2 Jul 17:47

Mixing # and : in strided ranges

Folks who have been tinkering with Fortress may have noticed that  
strided ranges of the form lower:upper:stride haven't yet been  
implemented.  I'm in the process of thinking about how this might best  
be done.

The big question in my mind is how the # and : notations interact with  
a stride.  My ideal semantics look something like the following:

l:u:s  yields l, l+s, l+2s, ...  <= u (so u is a rigid upper bound on  
the enumeration).
l#n:s  yields l, l+s, l+2s, ... l+(n-1)s
    (so that n exactly dictates the number of items enumerated).

I raise this issue in part to get people's opinions, but also because  
I'll be implementing this by simply overloading the : operator, so  
that it should be possible to write something like:
   myArray.indices():2
And stride through the indices of myArray by 2.  But this will require  
some major revisions to the internals of the types involved; at  
present we do not distinguish l#s from l:(l+s-1) and we would need to  
make that distinction in order for this code to work as we might expect.

-Jan-Willem Maessen

Victor Luchangco | 2 Jul 19:27

Re: Mixing # and : in strided ranges


On Jul 2, 2008, at 11:51 AM, Jan-Willem Maessen wrote:

> Folks who have been tinkering with Fortress may have noticed that  
> strided ranges of the form lower:upper:stride haven't yet been  
> implemented.  I'm in the process of thinking about how this might  
> best be done.
>
> The big question in my mind is how the # and : notations interact  
> with a stride.  My ideal semantics look something like the following:
>
> l:u:s  yields l, l+s, l+2s, ...  <= u (so u is a rigid upper bound  
> on the enumeration).
> l#n:s  yields l, l+s, l+2s, ... l+(n-1)s
>    (so that n exactly dictates the number of items enumerated).
>
> I raise this issue in part to get people's opinions, but also  
> because I'll be implementing this by simply overloading the :  
> operator, so that it should be possible to write something like:
>   myArray.indices():2
> And stride through the indices of myArray by 2.  But this will  
> require some major revisions to the internals of the types  
> involved; at present we do not distinguish l#s from l:(l+s-1) and  
> we would need to make that distinction in order for this code to  
> work as we might expect.

We also need to make `#' higher precedence than`:' (or equal  
precedence and left-associative) if we want to be able to write l#n:s  
rather than (l#n):s.

(Continue reading)


Gmane