What's left to do for a stable D2?
retard
re at tard.com.invalid
Sat Jan 23 05:30:00 PST 2010
Fri, 22 Jan 2010 15:27:02 -0500, bearophile wrote:
> Thank you for your answers Simen kjaeraas.
>
>>No need for them when we have this: S s = S( 4 );<
>
> If you have to initialize an array of many structs you have to repeat
> the name of the struct many times, this is redundant, and takes more
> space (and if you don't use an IDE it needs more time to type):
>
> struct Vector2 { double x, y; }
>
> Vector2[] data1 = [{1,2}, {3,4}, {0,1}, {1,2}, {2,3}, {3,4}, {4,5},
> {5,6}, {6,7},
> {7,8}, {8,9}, {9,10}, {10,11}, {11,12}, {12,13},
> {13,14}, {14,15}, {15,16}, {16,17}, {17,18}, {18,19},
> {19,20}];
>
> Vector2[] data2 = [Vector2(0,1), Vector2(1,2), Vector2(2,3),
> Vector2(3,4),
> Vector2(4,5), Vector2(5,6), Vector2(6,7),
> Vector2(7,8), Vector2(8,9), Vector2(9,10),
> Vector2(10,11), Vector2(11,12), Vector2(12,13),
> Vector2(13,14), Vector2(14,15), Vector2(15,16),
> Vector2(16,17), Vector2(17,18), Vector2(18,19),
> Vector2(19,20)];
>
> void main() {}
I'd use something like this in higher level languages™:
case class Vector[T](x: T, y: T)
val pairs = List( (1,2), (3,4), (0,1), (2,3), (3,4), (4,5) )
val vectors = pairs map { case (a:Int, b:Int) => Vector(a,b) }
or
class Vector[T](x: T, y: T) { def this(xy: (T,T)) = this(xy._1, xy._2) }
val pairs = List( (1,2), (3,4), (0,1), (2,3), (3,4), (4,5) )
val vectors = pairs map (new Vector(_))
More information about the Digitalmars-d
mailing list