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() {}

That's interesting. I would tend to use a function to initialize such things, though, so I suspect such use cases are quite rare. Note that C-style struct initializers add a lot of complexity to the language.


Literals are allocated in the static data segment, and thus should be 
immutable.<

In Python I am used to modify the contents of array (list) literals, for 
example I can initialize them to some values and then change them. So I'd like 
array literals to be mutable, but I can live with them being immutable and dup 
them where necessary.

Currently, any use of array literals in D is a performance disaster.
Two days ago, I found that by changing one line of code in my app from:
immutable int [] setbits = [ 1, 2, 4, 8, 16, 32, 64, 128];
into
static immutable int [] setbits = [ 1, 2, 4, 8, 16, 32, 64, 128];

my entire app became about 5 times faster. That is ridiculous.
And such a clumsy syntax for something so simple.

Reply via email to