Jump to page: 1 2
Thread overview
Dynamic Array Initialisation
Nov 28, 2005
John C
Nov 28, 2005
James Dunne
Nov 28, 2005
John C
Nov 28, 2005
James Dunne
Nov 28, 2005
Ivan Senji
Array literal expression (was: Dynamic Array Initialisation)
Nov 28, 2005
Sai
Nov 28, 2005
BCS
Nov 28, 2005
John C
Nov 28, 2005
Tomás Rossi
Nov 29, 2005
John C
Nov 29, 2005
Don Clugston
Nov 29, 2005
John C
Nov 28, 2005
clayasaurus
Nov 28, 2005
Ivan Senji
November 28, 2005
What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here), and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?

D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.

While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight.


November 28, 2005
John C wrote:
> What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here), 

I wouldn't make such assumptions unless I've read it directly from one of Walter's posts.

> and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?
> 
> D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.

I haven't found a use for it yet - IMO it doesn't seem all that critical.

By competitor do you mean C#?  I'd hardly call it a competitor =P.  I use C# in my daily job, and have yet to find a good use for dynamic array initialization.  Mainly it's used as a workaround for things which could've been implemented better in the .NET framework.  I can't even think of any good examples off-hand since it's so rarely used.

If you mean C++, then I'm fairly certain C++ has no such feature (except perhaps in STL but we're talking language features here not library).

I'm not sure about Java, or any of the other lesser used OO languages like Eiffel, O'Caml, Ada, ML, Smalltalk, etc.  (I'm not lumping Java in with the lesser-used OO languages here, although I'd certainly like it to be =P)  I'm pretty sure at least one of these languages should have such a feature, but if not I wouldn't be surprised.

> 
> While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight. 
> 

I suggest patience.  I've heard Walter has a very long TODO list, with many more items taking higher priority than this.  It's merely syntactic sugar.
November 28, 2005
John C wrote:
> What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here), and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?

I think it should because it is souch a fundamental feature.

> 
> D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.
> 
> While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight. 
> 

I would also like to add something that 100% isn't goint to be in D1.0 an it is dynamic alocation of rectangular arrays. It is something I miss and is also IMO a very fundamental thing for a language that is so good with arrays to have.
November 28, 2005
"James Dunne" <james.jdunne@gmail.com> wrote in message news:dmfjdj$2o05$1@digitaldaemon.com...
> John C wrote:
>> What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here),
>
> I wouldn't make such assumptions unless I've read it directly from one of Walter's posts.
>
>> and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?
>>
>> D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.
>
> I haven't found a use for it yet - IMO it doesn't seem all that critical.
>
> By competitor do you mean C#?  I'd hardly call it a competitor =P.

Competitors. Plural. Other C-like languages in general.

> If you mean C++, then I'm fairly certain C++ has no such feature (except perhaps in STL but we're talking language features here not library).

In C/C++, you do this to initialise an array:
    int data[] = { 1, 2, 3 };

To initialise a multidimensional array, the syntax is this:
    int data[][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };

>
> I'm not sure about Java, or any of the other lesser used OO languages like Eiffel, O'Caml, Ada, ML, Smalltalk, etc.  (I'm not lumping Java in with the lesser-used OO languages here, although I'd certainly like it to be =P)  I'm pretty sure at least one of these languages should have such a feature, but if not I wouldn't be surprised.

Java:
    int[] data = new int[] { 1, 2, 3, 4 };

>
>>
>> While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight.
>
> I suggest patience.  I've heard Walter has a very long TODO list, with many more items taking higher priority than this.  It's merely syntactic sugar.

So are most language constructs.


November 28, 2005
James Dunne wrote:
> John C wrote:
> 
>> What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here), 
> 
> 
> I wouldn't make such assumptions unless I've read it directly from one of Walter's posts.
> 
>> and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?
>>
>> D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.
> 
> 
> I haven't found a use for it yet - IMO it doesn't seem all that critical.
> 
> By competitor do you mean C#?  I'd hardly call it a competitor =P.  I use C# in my daily job, and have yet to find a good use for dynamic array initialization.  Mainly it's used as a workaround for things which could've been implemented better in the .NET framework.  I can't even think of any good examples off-hand since it's so rarely used.
> 
> If you mean C++, then I'm fairly certain C++ has no such feature (except perhaps in STL but we're talking language features here not library).

You have to remember that D prides itself in having core features builtin instead of needing a seperate library.

> 
> I'm not sure about Java, or any of the other lesser used OO languages like Eiffel, O'Caml, Ada, ML, Smalltalk, etc.  (I'm not lumping Java in with the lesser-used OO languages here, although I'd certainly like it to be =P)  I'm pretty sure at least one of these languages should have such a feature, but if not I wouldn't be surprised.
> 
>>
>> While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight.
> 
> 
> I suggest patience.  I've heard Walter has a very long TODO list, with many more items taking higher priority than this.  It's merely syntactic sugar.
November 28, 2005
John C wrote:
> "James Dunne" <james.jdunne@gmail.com> wrote in message news:dmfjdj$2o05$1@digitaldaemon.com...
> 
>>John C wrote:
>>
>>>What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here),
>>
>>I wouldn't make such assumptions unless I've read it directly from one of Walter's posts.
>>
>>
>>>and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?
>>>
>>>D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.
>>
>>I haven't found a use for it yet - IMO it doesn't seem all that critical.
>>
>>By competitor do you mean C#?  I'd hardly call it a competitor =P.
> 
> 
> Competitors. Plural. Other C-like languages in general.
> 

Right.  I gathered as much; I was just trying to demonstrate a few examples of competitors.

> 
>>If you mean C++, then I'm fairly certain C++ has no such feature (except perhaps in STL but we're talking language features here not library).
> 
> 
> In C/C++, you do this to initialise an array:
>     int data[] = { 1, 2, 3 };
> 
> To initialise a multidimensional array, the syntax is this:
>     int data[][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
> 
> 

This isn't what you're requesting then.  AFAIK D can do this.  This is just static array initialization.  There's nothing truly dynamic in the sense of "run-time" dynamic here.  One could say this is dynamic in the sense that the array dimension was not explicitly specified, but it can be inferred from the initialization data.  Does D do this?  If not I agree it would be nice, but not critical.

To be honest, I'm not sure what exactly this does in C++..  Last I recall I don't think it creates a dynamic array.  Then again, there is no such thing as a dynamic array in C++.  lol

>>I'm not sure about Java, or any of the other lesser used OO languages like Eiffel, O'Caml, Ada, ML, Smalltalk, etc.  (I'm not lumping Java in with the lesser-used OO languages here, although I'd certainly like it to be =P)  I'm pretty sure at least one of these languages should have such a feature, but if not I wouldn't be surprised.
> 
> 
> Java:
>     int[] data = new int[] { 1, 2, 3, 4 };
> 

This is more what you're after I'm thinking, and it was what I was originally talking about with regard to C#.  It looks exactly the same in C#, and is just as useless =P.

> 
>>>While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight.
>>
>>I suggest patience.  I've heard Walter has a very long TODO list, with many more items taking higher priority than this.  It's merely syntactic sugar.
> 
> 
> So are most language constructs. 
> 

Not necessarily.
November 28, 2005
James Dunne wrote:
> John C wrote:
>>
>> In C/C++, you do this to initialise an array:
>>     int data[] = { 1, 2, 3 };
>>
>> To initialise a multidimensional array, the syntax is this:
>>     int data[][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
>>
>>
> 
> This isn't what you're requesting then.  AFAIK D can do this.  

No it can't.

> This is just static array initialization.  

No it isn't.
The thing that is being asked for is this:

int[] numbers = [x+y, y+z, z+x];

Try to do this in D. The static/const trick will not work if x,y,z are non-constant variables so you will have to do:

int[] numbers = new int[3];
numbers[0] = x+y;
numbers[1] = y+z;
numbers[2] = z+x;

Wich is nicer is obvious.

> There's nothing truly dynamic in the sense of "run-time" dynamic here.  

There should be.
November 28, 2005
"James Dunne" <james.jdunne@gmail.com> wrote in message news:dmfu0g$30f0$1@digitaldaemon.com...
> John C wrote:
>> "James Dunne" <james.jdunne@gmail.com> wrote in message news:dmfjdj$2o05$1@digitaldaemon.com...
>>
>>>John C wrote:
>>>
>>>>What's holding back the implementation of dynamic array initialisation? I know it's scheduled to be included post-1.0 (or so I've read here),
>>>
>>>I wouldn't make such assumptions unless I've read it directly from one of Walter's posts.
>>>
>>>
>>>>and I'm aware of (and am using) the well-known workarounds (assigning a static array/template with variadic args), but shouldn't this be in the language for its big debut?
>>>>
>>>>D aims to have great array-handling capabilities, and for the most part it does, yet the fact that a built-in syntax for creating a dynamic array and filling it with values is missing seems incompatible with such an aim. All of D's main competitors have such a feature, and to be honest it's a pretty fundamental one to any language.
>>>
>>>I haven't found a use for it yet - IMO it doesn't seem all that critical.
>>>
>>>By competitor do you mean C#?  I'd hardly call it a competitor =P.
>>
>>
>> Competitors. Plural. Other C-like languages in general.
>>
>
> Right.  I gathered as much; I was just trying to demonstrate a few examples of competitors.

I should have been clearer. And yes, there are numerous languages that don't allow array assignment on declaration, but you just need to Google a little to see their users asking for ways to do exactly that. It's not so rare as you have found in your own experience.

>
>>
>>>If you mean C++, then I'm fairly certain C++ has no such feature (except perhaps in STL but we're talking language features here not library).
>>
>>
>> In C/C++, you do this to initialise an array:
>>     int data[] = { 1, 2, 3 };
>>
>> To initialise a multidimensional array, the syntax is this:
>>     int data[][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
>>
>>
>
> This isn't what you're requesting then.  AFAIK D can do this.  This is just static array initialization.  There's nothing truly dynamic in the sense of "run-time" dynamic here.  One could say this is dynamic in the sense that the array dimension was not explicitly specified, but it can be inferred from the initialization data.  Does D do this?  If not I agree it would be nice, but not critical.

In D, the elements in the initialiser must be constants. C/C++ allows this, D doesn't:

int el = 2;
int data[] = { el, el + 1 };

>
> To be honest, I'm not sure what exactly this does in C++..  Last I recall I don't think it creates a dynamic array.  Then again, there is no such thing as a dynamic array in C++.  lol
>
>>>I'm not sure about Java, or any of the other lesser used OO languages like Eiffel, O'Caml, Ada, ML, Smalltalk, etc.  (I'm not lumping Java in with the lesser-used OO languages here, although I'd certainly like it to be =P)  I'm pretty sure at least one of these languages should have such a feature, but if not I wouldn't be surprised.
>>
>>
>> Java:
>>     int[] data = new int[] { 1, 2, 3, 4 };
>>
>
> This is more what you're after I'm thinking, and it was what I was originally talking about with regard to C#.  It looks exactly the same in C#, and is just as useless =P.

Please explain why it's useless. You might as well say that constructors on classes are useless.

>
>>
>>>>While the current focus on bug fixing is laudable, this long-standing omission if beginning to feel like an oversight.
>>>
>>>I suggest patience.  I've heard Walter has a very long TODO list, with many more items taking higher priority than this.  It's merely syntactic sugar.
>>
>>
>> So are most language constructs.
>
> Not necessarily.


November 28, 2005
Its called "Array literal expression"

It is mentioned in "future features" page http://www.digitalmars.com/d/future.html

But I too think it is fundamental and most basic feature. What is the reason for it being a less priority feature ? What is soo hard in implementing it ?

Currently I am using code like

Matrix m = new Matrix(4, 1);
m.array[0] = x;
m.array[1] = y;
m.array[2] = z;
m.array[3] = 1;

I whish I could do

double[] arr = [x, y, z, 1];
Matrix m = new Matrix(arr);

It gets real ugly for large dimensions.

Sai


November 28, 2005
/**
this with array ops would work.
**/

int main()
{
int a = 1, b = 2, c = 3;
int x = 4, y = 5, z = 6;
int[] array = make!(int)(&a, &b, &c);
int[] array2 = make!(int)(&a, &b, &c);

array[] += arry2[];

foreach(int i, int j; array)
printf("[%d] = %d\n", i,j);

return 2;
}


template make(T)
{
T[] make(T*[] p ...)
{
T[] ret = new T[p.length];

foreach(int i, T* v; p)
ret[i] = *v;

return ret;
}
}




In article <dmfuq5$310j$1@digitaldaemon.com>, Ivan Senji says...
>
>James Dunne wrote:
>> John C wrote:
>>>
>>> In C/C++, you do this to initialise an array:
>>>     int data[] = { 1, 2, 3 };
>>>
>>> To initialise a multidimensional array, the syntax is this:
>>>     int data[][4] = { { 0, 1, 2, 3 }, { 4, 5, 6, 7 } };
>>>
>>>
>> 
>> This isn't what you're requesting then.  AFAIK D can do this.
>
>No it can't.
>
>> This is just static array initialization.
>
>No it isn't.
>The thing that is being asked for is this:
>
>int[] numbers = [x+y, y+z, z+x];
>
>Try to do this in D. The static/const trick will not work if x,y,z are non-constant variables so you will have to do:
>
>int[] numbers = new int[3];
>numbers[0] = x+y;
>numbers[1] = y+z;
>numbers[2] = z+x;
>
>Wich is nicer is obvious.
>
>> There's nothing truly dynamic in the sense of "run-time" dynamic here.
>
>There should be.


« First   ‹ Prev
1 2