www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Improving (foreach) ranges

reply Robert Clipsham <robert octarineparrot.com> writes:
With the introduction of std.parallelism, I've been wondering about the 
following:

foreach (i; 0..100)
{
}

For most uses of foreach, you can just wrap the range in parallel(), but 
with a foreach range statement you can't do this. Of course iota() could 
be used:

foreach (i; parallel(iota(0, 100)))
{
}

But that seems inconsistent. What are people's thoughts on making the 
syntax a..b more general, so you can do eg:

void foo(int[]);
foo(0..100);

Although, I seem to recall seeing this conversation elsewhere, let me 
know if this is the case.

-- 
Robert
http://octarineparrot.com/
Jun 09 2011
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
Yeah there was a big discussion about this IIRC. I can't recall the
exact link to the topic, sorry.
Jun 09 2011
parent reply "Robert Jacques" <sandford jhu.edu> writes:
On Thu, 09 Jun 2011 19:58:34 -0400, Andrej Mitrovic  
<andrej.mitrovich gmail.com> wrote:

 Yeah there was a big discussion about this IIRC. I can't recall the
 exact link to the topic, sorry.
I know one of them was during tuple discussions. i.e. to use a..b..c instead of (a,b,c) The principal rational was a) '(,)' already has other meanings in D and b) '..' would allow for multi-dimensional slicing. But people felt this was ugly. And the multi-dimensional slicing discussions tend to advocate mapping a..b to [a,b].
Jun 09 2011
parent eles <eles eles.com> writes:
 And the multi-dimensional slicing discussions tend to advocate mapping
 a..b to [a,b].
which would be such a shame...
Jun 11 2011