static array literal syntax request: auto x=[1,2,3]S;

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 15 00:15:21 PDT 2012


On Friday, June 15, 2012 09:09:48 Don Clugston wrote:
> On 10/06/12 23:43, Jonathan M Davis wrote:
> > On Sunday, June 10, 2012 23:23:57 Mehrdad wrote:
> >> I honestly don't see the POINT of having a "dynamic array
> >> literal".
> >> 
> >> What's the point of making the literals dynamic?
> >> 
> >> They should all be static, and only converted to dynamic if
> >> necessary from the context.
> >> 
> >> But I really don't see the benefit of allocating them on the heap
> >> just because we can... perhaps someone can enlighten me?
> > 
> > In the vast majority of cases where an array literal is used, it's
> > assigned to a dynamic array.
> 
> I doubt that very much. I know it's not true in my code, I use array
> literals almost exclusively for immutable values.
> Usually if you are initializing an array, where you will modify the
> elements later, you want all values to be the same.
> 
> I argued that array literals should be immutable, just as string
> literals are. But I lost.

What does immutability have to do with static vs dynamic?

immutable a = [0, 1, 2, 3];

results in an immutable(int[]), not immutable(int[4]).

- Jonathan M Davis


More information about the Digitalmars-d mailing list