tuple-syntax

electricface electricface at qq.com
Tue Mar 19 06:10:38 UTC 2024


On Tuesday, 19 March 2024 at 05:43:25 UTC, electricface wrote:
> On Sunday, 17 March 2024 at 20:20:52 UTC, Dom DiSc wrote:
>> I just viewed the D-Conf online talk about new syntax for 
>> tuples and had an idea I need to suggest:
>>
>> One of the proposals was to use normal round brackets. But 
>> this would required to use something special to distinguish 
>> one-element tuples from from a parenthesized expression. It 
>> suggested a trailing comma for this case. But it has the 
>> second flaw that it remains unclear how to express an empty 
>> tuple unambiguously.
>>
>> So, how about _always_ requiring a trailing comma?
>> This would make for a consistent syntax: (,) empty tuple, (x,) 
>> one-element tuple, (x,y,) two element tuple ...
>>
>> Just an idea.
>
> I have also reviewed the documentation for the tuple speech. 
> Below is the tuple syntax that I have designed, which I believe 
> is more structured and easier to distinguish:
>


named tuple:
```
(int:a-) t1 = (a:1, EOT);
(int:a-int:b) t2 = (a: 1, b: 2);

func( (int:a-int:b)(a, b) ) => a + b;
auto tab =  (a: 1, b: 2);
func( tab ); // ok

func2(int a , int b) => a + b;

func2( (b:2, a: 1).expand ); // ok
func2( (b:2, a: 1) ); // err
```


More information about the Digitalmars-d mailing list