On Wed, 12 Aug 2009 12:41:20 -0400, Ali Cehreli <[email protected]> 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