why static array can be reassigned with new allocation?

mw mingwu at gmail.com
Sat Oct 15 19:07:04 UTC 2022


On Saturday, 15 October 2022 at 18:44:04 UTC, mw wrote:
> Regarding the syntax problem I want to make my point clear 
> again: different semantics (variable assignment a = b v.s 
> content assignment a[] = b[]) should have different syntax, 
> *regardless* they are static or dynamic array.
>
> As more fun with your example:
>
>      a = b.dup;  // so this is content assignment?
>      writeln(a is b, " ", a == b); // false true

Sorry, I just realized that `a = b.dup` is also var assignment: 
b.dup will create a new array and assigned to a, hence `a is b` 
is false.

>      a = b;      // this is var assignment?
>      writeln(a is b, " ", a == b); // true true
>
> This current syntax in D is as clear as mud.




More information about the Digitalmars-d mailing list