DIP19: Remove comma operator from D and provision better syntactic support for tuples

Eldar Insafutdinov e.insafutdinov at gmail.com
Mon Sep 24 08:23:24 PDT 2012


On Monday, 24 September 2012 at 14:52:21 UTC, Steven 
Schveighoffer wrote:
>
> (int[]) x;
>
> int a = x.length;
>
> is a == 0 or 1?
>
> I agree with Andrei, we need something different.


This is exactly the question I was going to ask ...

>
> I don't profess to be even close to an expert on tuples, but I 
> feel they should be built-in to the language, since they are 
> actually language constructs that we are declaring types for.
>
> Without any research or investigation, what about using a 
> different set of delimiters for tuples?  Like {1,2,3}

... and exactly the syntax I was going to propose! {} is already 
used in C languages for heterogeneous data 
structures(structs/classes, JSON etc). Using () creates too many 
special cases, especially in generic programming and seeing how 
other languages are dealing with them we'd rather avoid them from 
the very beginning.

> Right now, I think that is reserved for static struct 
> initializers.  But can't those be considered a tuple also?  
> Someone will probably destroy this 10 milliseconds after I send 
> it :)
>
> -Steve

It would be awesome if we could make tuples generic initializers 
for various data types in D. Not just structs but for instance 
arrays:

int[] a = {1, 2, 3, 4};

Compiler possesses enough type information to know that this 
tuple could be converted to the int[].

P.S. The only collision I see with {} is a delegate literal, but 
to be honest it's not worth the merit and quite confusing in 
fact. There are 3 other ways to define a delegate in D which will 
cover all of the user's needs.


More information about the Digitalmars-d mailing list