Questions about the slice operator

ixid nuaccount at gmail.com
Tue Apr 3 18:29:03 PDT 2012


I understand the basic use to slice an array but what about these:

foreach(i;0..5)
     dostuff;

That works yet this does not:

foreach(i;parallel(0..5))
     dostuff;

Why not let this work? It'd seem like a natural way of writing a 
parallel loop. For some reason:

foreach(i;[0,1,2,3,4])
     dostuff;

This performs far more slowly than the first example and only as 
fast as it when parallelized with a ~150ms function for each 
iteration.

What kind of data is it and how is it behaving? If it can do what 
it does in the first example why not let it do something like 
this:

int[] arr = 0..5; //arr = [0,1,2,3,4]

One final thought- why is the array function required to convert 
a lazy Result to an eager one? If you explicitly set something 
like int[] blah = lazything why not have it silently convert 
itself?


More information about the Digitalmars-d-learn mailing list