Using map instead of iteration

2011-03-06 Thread Russel Winder
I have a code fragment: auto threads = new Thread[numberOfThreads] ; foreach ( i ; 0 .. numberOfThreads ) { void delegate ( ) closedPartialSum ( ) { immutable id = i ; return ( ) { partialSum ( id , sliceSize , delta ) ; } ; } threads[i] = new Thread ( closedPartialSu

Re: Using map instead of iteration

2011-03-06 Thread Simen kjaeraas
Russel Winder wrote: I have a code fragment: auto threads = new Thread[numberOfThreads] ; foreach ( i ; 0 .. numberOfThreads ) { void delegate ( ) closedPartialSum ( ) { immutable id = i ; return ( ) { partialSum ( id , sliceSize , delta ) ; } ; } threads[i] = new T

Re: Using map instead of iteration

2011-03-06 Thread spir
On 03/06/2011 02:43 PM, Russel Winder wrote: I have a code fragment: auto threads = new Thread[numberOfThreads] ; foreach ( i ; 0 .. numberOfThreads ) { void delegate ( ) closedPartialSum ( ) { immutable id = i ; return ( ) { partialSum ( id , sliceSize , delta ) ; } ;

Re: Using map instead of iteration

2011-03-06 Thread Russel Winder
On Sun, 2011-03-06 at 14:57 +0100, Simen kjaeraas wrote: [ . . . ] > You should use std.range.iota(0,numberOfThreads) instead of > 0..numberOfThreads. Having a..b return a general interval range > has been proposed numerous times, but nothing has been implemented as > of yet. Thanks for this point

Re: Using map instead of iteration

2011-03-06 Thread Russel Winder
On Sun, 2011-03-06 at 16:25 +0100, spir wrote: [ . . . ] > Without trying to study the code's detainls: "( 0 .. numberOfThreads )" has > very few chances to be accepted by the parser ;-) > Note: there is no interval literal in D. Instead uses of i..j in slicing and > foreach both are pure syntact

Re: Using map instead of iteration

2011-03-06 Thread bearophile
Russel Winder: > Perhaps this needs review. All modern language now have this as an > integral way of describing a sequence of values. We have discussed about this not too much time ago. See the enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=5395 D language design is too muc

Re: Using map instead of iteration

2011-03-06 Thread Jonathan M Davis
On Sunday 06 March 2011 05:57:12 Simen kjaeraas wrote: > You should use std.range.iota(0,numberOfThreads) instead of > 0..numberOfThreads. Having a..b return a general interval range > has been proposed numerous times, but nothing has been implemented as > of yet. I'm sure that part of the problem

Re: Using map instead of iteration

2011-03-06 Thread bearophile
Jonathan M Davis: > I'm sure that part of the problem is the fact that a .. b is also used in > slicing, where it does not mean the same thing It means the same thing, with a interval literal. > - that and iota works just fine, Currently it has a design bug that I've underlined. > and incr

Re: Using map instead of iteration

2011-03-06 Thread Jonathan M Davis
On Sunday 06 March 2011 17:20:33 bearophile wrote: > Jonathan M Davis: > > I'm sure that part of the problem is the fact that a .. b is also used in > > slicing, where it does not mean the same thing > > It means the same thing, with a interval literal. > > > - that and iota works just fine, > >

Re: Using map instead of iteration

2011-03-07 Thread Russel Winder
On Sun, 2011-03-06 at 17:41 -0800, Jonathan M Davis wrote: [ . . . ] > If anything, I'd argue to simply remove .. from foreach and have iota be the > way > to do it. The only other inconsistency is with case statements, but making > them > have an open right end would likely be problematic (not

Re: Using map instead of iteration

2011-03-29 Thread Don
bearophile wrote: Russel Winder: Perhaps this needs review. All modern language now have this as an integral way of describing a sequence of values. We have discussed about this not too much time ago. See the enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=5395 D language