tuple-syntax

electricface electricface at qq.com
Tue Mar 19 06:59:48 UTC 2024


On Tuesday, 19 March 2024 at 06:10:38 UTC, electricface wrote:
> 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.

> 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
> ```

with templates:

`Vector!(-)` represents a vector of empty tuples.
`Vector!(int-)` represents a vector of tuples with 1 int element.
`Vector!(int-int)` represents a vector of tuples with 2 int 
elements.

`(Vector!int-Vector!int)` represents a tuple of 2 vectors, where 
the first element's type is Vector!int and the second element's 
type is also the same. It should not be understood as 
`Vector!(int-Vector!int)`.
`(Vector!(int)-Vector!(int))` same as the previous one.

`(Vector!(int-int)-Vector!(int-int))` represents a tuple of 2 
vectors, where the first element's type is `Vector!(int-int)` and 
the second element's type is also the same.


More information about the Digitalmars-d mailing list