Better distinguishing reference and value in the syntax?

Alex Rønne Petersen xtzgzorex at gmail.com
Mon Jan 2 04:18:36 PST 2012


On 02-01-2012 06:25, Gou Lingfeng wrote:
> D's definitions of "is" and "==" have so much redundency. That might
> indicate some flaw. If references and values (for classes and arrays)
> could be clearly distinguished in the syntax, the "is" operator is not
> necessary at all.

Of course it is. 'is' is strictly identity, while == would call an 
overloaded opEquals, if any exists. This difference in semantics is 
*very* important when you do *not* want to call opEquals.

>
> A related thing is element-wise operation. Consider
> string[] a;
> string[] b;
> string[] c;
> ...
> c[1..3]=a[1..3]~b[1..3];
>
> and,
>
> int[] a;
> int[] b;
> int[] c;
> ...
> c[1..3]=a[1..3]+b[1..3];
>
> The two pieces are very much similar, and I expect similar results. But
> D doesn't provide element-wise concatenation, because it's not clear in
> the syntax whether a[1..3] is a reference (for simple array
> concatenation) or a value (for element-wise concatenation).
>

- Alex


More information about the Digitalmars-d mailing list