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

Timon Gehr timon.gehr at gmx.ch
Sun Sep 23 17:44:45 PDT 2012


On 09/24/2012 02:28 AM, deadalnix wrote:
> Le 24/09/2012 02:21, Timon Gehr a écrit :
>> On 09/24/2012 02:00 AM, deadalnix wrote:
>>> Le 24/09/2012 01:28, Timon Gehr a écrit :
>>>> I agree with Andrei. Single element tuples need to support the same
>>>> operations as tuples of other arities do.
>>>
>>> Obviously it should. The whole point is that you can implicitly cast a 1
>>> element tuple into the element and vice versa.
>>>
>>> like :
>>> (int) a = (3); // a is a tuple of 1 element.
>>> int b = a; // Implicit tuple unpack.
>>> a = b; // Implicit tuple packing.
>>
>>
>> Well, I do not want parentheses to randomly hide members.
>>
>> (a ~ b).length
>
> Then it easy to add a comma to create a one element tuple. IE:
>
> (a ~ b).length == a.length + b.length
> (a ~ b,).length == 1

The motivation for having these conversions was syntactic ambiguity.

If there is none, just do it like this:

(create_tuple,)
get_value[0]


More information about the Digitalmars-d mailing list