tuple-syntax
electricface
electricface at qq.com
Tue Mar 19 09:06:35 UTC 2024
On Tuesday, 19 March 2024 at 06:59:48 UTC, electricface wrote:
> 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.
>
>
lambda function:
```
auto lambda0 = ( (-) t0 ) => 0;
auto lambda1 = ( (int-) (a, EOT) ) => a;
auto lambda2 = ( (int-int) (a, b) ) => a + b;
or:
auto lambda2 = ( (a,b) ) => a + b; // type similar to auto
function( (T-T) t2)
but:
auto lambdaArg2 = ( a, b ) => a + b; // type similar to auto
function(T a, T b)
```
foreach:
```
auto ts = [(1,2), (3,4), (5,6)];
// with unpack:
foreach( (int-int)(a, b); ts) {
writeln(a," ", b) // 1 2\n3 4\n5 6
}
foreach( (a, b); ts) {
writeln(a," ", b) // 1 2\n3 4\n5 6
}
foreach(int i, (int-int)(a, b); ts) {
writeln(i," ",a," ", b) //0 1 2\n1 3 4\n2 5 6
}
// with unpack:
foreach( i, (a, b); ts) {
writeln(i," ",a," ", b) //0 1 2\n1 3 4\n2 5 6
}
```
return a tuple :
```
(-) func0() {
return (EOT);
}
auto func0() {
return (EOT);
}
auto lambda0 = () => (EOT);
(int-) func1() {
return (1, EOT);
}
auto func1() {
return (1, EOT);
}
auto lambda1 = () => (1, EOT);
(int-int) func2() {
return (1,2);
}
auto func2() {
return (1,2);
}
auto lambda2 = () => (1, 2);
```
More information about the Digitalmars-d
mailing list