Is [ 0, 1, 2 ] an immutable array?
Steven Schveighoffer
schveiguy at yahoo.com
Wed Aug 12 10:08:08 PDT 2009
On Wed, 12 Aug 2009 12:41:20 -0400, Ali Cehreli <acehreli at yahoo.com> wrote:
> Steven Schveighoffer Wrote:
>
>> > int[] a = [ 0, 1, 2 ];
>> > a[0] = 42;
>
>> No, it's a mutable array. It's one of the quirks of D2 that bugs me. A
>> string literal is an immutable array but a normal array literal actually
>> allocates new space on the heap for the array every time you use it. So
>> if you assign the same literal to 2 different variables, they are 2
>> separate copies of the array.
>>
>> I think the behavior should be identical to strings.
>
> I agree. I thought that D was a good first language to teach, so I've
> started to write a tutorial; but I am having big difficultly extracting
> the semantics of arrays and slices.
>
> I still can't understand how to explain dynamic arrays and slices even
> to myself yet. :D
Hold off. Arrays and slices are about to change drastically (see thread
on T[new] in digitalmars.D)
-Steve
More information about the Digitalmars-d-learn
mailing list