Christopher Wright wrote: > Daniel Keep wrote: >> unordered foreach( i ; 0..10 ) >> { >> ... >> } > > If the foreach body consists of a pure function call, then the foreach > is reorderable and parallelizable. > > Considering that, you could save a keyword and use 'pure' rather than > 'foreach'. > > If you like the idea, send Walter a patch for this.
I *don't* like this; I was pointing out that it doesn't work. Let's say the body is pure. Pure means that it only depends on its arguments and doesn't use or mutate any non-immutable external state. So you do lots of computations based on i. Now, how do you store the result? You *can't*, because that would involve changing state external to the loop. As Tim said, you can go to lock-based programming. But that's just reinventing the problem we have today with multithreading: it's virtually impossible to do it right. The point is that by the time you've munged foreach or whatever into a state suitable for automatic parallelisation, you've likely just gone and reinvented the map function, so you might as well just cut to the chase and use that. That plus pure functions should make it virtually impossible to get it *wrong*. -- Daniel