digitalmars.D - Dynamic Array Initialisation
- John C (12/12) Nov 28 2005 What's holding back the implementation of dynamic array initialisation? ...
- James Dunne (19/34) Nov 28 2005 I wouldn't make such assumptions unless I've read it directly from one
- John C (10/39) Nov 28 2005 Competitors. Plural. Other C-like languages in general.
- James Dunne (16/78) Nov 28 2005 Right. I gathered as much; I was just trying to demonstrate a few
- Ivan Senji (13/28) Nov 28 2005 No it isn't.
- John C (12/89) Nov 28 2005 I should have been clearer. And yes, there are numerous languages that d...
- Tomás Rossi (9/105) Nov 28 2005 I agree. You could write the same programs in assembly (if you're nuts)....
- Jarrett Billingsley (12/17) Nov 28 2005 How about:
- John C (6/23) Nov 29 2005 The compiler treats strings as a special case. It doesn't see "hello" an...
- Don Clugston (15/52) Nov 29 2005 There are a huge number of related issues. When I asked recently if we
- John C (3/55) Nov 29 2005 I appreciate you reasoning it through. That's all I wanted to hear.
- clayasaurus (3/49) Nov 28 2005 You have to remember that D prides itself in having core features
- Ivan Senji (6/21) Nov 28 2005 I would also like to add something that 100% isn't goint to be in D1.0
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.
Nov 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. 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.
Nov 28 2005
"James Dunne" <james.jdunne gmail.com> wrote in message news:dmfjdj$2o05$1 digitaldaemon.com...John C wrote:Competitors. Plural. Other C-like languages in general.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.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 };So are most language constructs.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.
Nov 28 2005
John C wrote:"James Dunne" <james.jdunne gmail.com> wrote in message news:dmfjdj$2o05$1 digitaldaemon.com...Right. I gathered as much; I was just trying to demonstrate a few examples of competitors.John C wrote:Competitors. Plural. Other C-like languages in general.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.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++. lolIf 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 is more what you're after I'm thinking, and it was what I wasI'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 };Not necessarily.So are most language constructs.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.
Nov 28 2005
James Dunne wrote:John C wrote:No it can't.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.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.
Nov 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
Nov 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:No it can't.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.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.
Nov 28 2005
"James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...John C wrote: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."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfjdj$2o05$1 digitaldaemon.com...Right. I gathered as much; I was just trying to demonstrate a few examples of competitors.John C wrote:Competitors. Plural. Other C-like languages in general.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.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 };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.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 } };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++. lolPlease explain why it's useless. You might as well say that constructors on classes are useless.This is more what you're after I'm thinking, and it was what I wasI'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 };Not necessarily.So are most language constructs.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.
Nov 28 2005
In article <dmg00l$lk$1 digitaldaemon.com>, John C says..."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...I agree. You could write the same programs in assembly (if you're nuts). High level languages are essentially abstractions of low level ones (at least practically speaking). I would say, in an exaggerated manner, that high level languages are basically complex syntactic sugar constructions. A lot of D's beauty resides in it's beautiful syntax sugars.John C wrote: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."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfjdj$2o05$1 digitaldaemon.com...Right. I gathered as much; I was just trying to demonstrate a few examples of competitors.John C wrote:Competitors. Plural. Other C-like languages in general.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.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 };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.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 } };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++. lolPlease explain why it's useless. You might as well say that constructors on classes are useless.This is more what you're after I'm thinking, and it was what I wasI'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 };So are most language constructs.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.Why not? IMHO if you make such an imprecise affirmation, you have to explain why. TomNot necessarily.
Nov 28 2005
"James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...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.How about: char[] str = "hello"; It's a dynamic array with an initializer. In other words, D can already do it, just not with any types besides (w|d)char. As a point of interest, you can use a string of dchars to initialize an int[]: int[] a = cast(int[])cast(void[])"\U00000001\U00000002\U00000003"d; foreach(int i; a) writefln(i); So the mechanism is there..
Nov 28 2005
"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:dmgln8$gno$1 digitaldaemon.com..."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.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.How about: char[] str = "hello"; It's a dynamic array with an initializer. In other words, D can already do it, just not with any types besides (w|d)char.As a point of interest, you can use a string of dchars to initialize an int[]: int[] a = cast(int[])cast(void[])"\U00000001\U00000002\U00000003"d; foreach(int i; a) writefln(i); So the mechanism is there..Is it? As shown above, you can't initialise char[] with an array of chars, only with a string.
Nov 29 2005
John C wrote:"Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:dmgln8$gno$1 digitaldaemon.com...There are a huge number of related issues. When I asked recently if we could have const int [] a = [1, 2, 3] ~ [4, 5, 6]; evaluated at compile time, Walter said: "The reason it does not currently work is because there is no syntax for array literals as a PrimaryExpression. This is fixable, but not at the moment." I conclude: (a) Including array literals will involve major structural change in both the parser and semantic analyser. Many bugs will be introduced, it will take a long time for the compiler to stabilise afterwards. (b) Walter does intend to do it eventually. Probably, a lot of minor things need to be tidied up before it can be considered."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.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.How about: char[] str = "hello"; It's a dynamic array with an initializer. In other words, D can already do it, just not with any types besides (w|d)char.As a point of interest, you can use a string of dchars to initialize an int[]: int[] a = cast(int[])cast(void[])"\U00000001\U00000002\U00000003"d; foreach(int i; a) writefln(i); So the mechanism is there..Is it? As shown above, you can't initialise char[] with an array of chars, only with a string.
Nov 29 2005
"Don Clugston" <dac nospam.com.au> wrote in message news:dmhkl6$1ebj$1 digitaldaemon.com...John C wrote:I appreciate you reasoning it through. That's all I wanted to hear."Jarrett Billingsley" <kb3ctd2 yahoo.com> wrote in message news:dmgln8$gno$1 digitaldaemon.com...There are a huge number of related issues. When I asked recently if we could have const int [] a = [1, 2, 3] ~ [4, 5, 6]; evaluated at compile time, Walter said: "The reason it does not currently work is because there is no syntax for array literals as a PrimaryExpression. This is fixable, but not at the moment." I conclude: (a) Including array literals will involve major structural change in both the parser and semantic analyser. Many bugs will be introduced, it will take a long time for the compiler to stabilise afterwards. (b) Walter does intend to do it eventually. Probably, a lot of minor things need to be tidied up before it can be considered."James Dunne" <james.jdunne gmail.com> wrote in message news:dmfu0g$30f0$1 digitaldaemon.com...The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.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.How about: char[] str = "hello"; It's a dynamic array with an initializer. In other words, D can already do it, just not with any types besides (w|d)char.As a point of interest, you can use a string of dchars to initialize an int[]: int[] a = cast(int[])cast(void[])"\U00000001\U00000002\U00000003"d; foreach(int i; a) writefln(i); So the mechanism is there..Is it? As shown above, you can't initialise char[] with an array of chars, only with a string.
Nov 29 2005
James Dunne wrote:John C wrote:You have to remember that D prides itself in having core features builtin instead of needing a seperate library.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. 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.
Nov 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.
Nov 28 2005