November 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...
>> 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.

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.

>> Not necessarily.

Why not? IMHO if you make such an imprecise affirmation, you have to explain why.

Tom
November 29, 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..


November 29, 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...
>> 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.

The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.

>
> 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.


November 29, 2005
John C wrote:
> "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...
>>
>>>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.
> 
> 
> The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.
> 
> 
>>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. 

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.


November 29, 2005
"Don Clugston" <dac@nospam.com.au> wrote in message news:dmhkl6$1ebj$1@digitaldaemon.com...
> John C wrote:
>> "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...
>>>
>>>>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.
>>
>>
>> The compiler treats strings as a special case. It doesn't see "hello" and ['h', 'e', 'l', 'l', 'o'] as the same thing.
>>
>>
>>>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.
>
> 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.
>
>

I appreciate you reasoning it through. That's all I wanted to hear.


1 2
Next ›   Last »