First Draft: Tuple Unpacking Syntax
Timon Gehr
timon.gehr at gmx.ch
Sun Jul 27 21:30:41 UTC 2025
On 7/27/25 08:31, Walter Bright wrote:
> This is a well written DIP. Congratulations!
>
> The forward range tuple is pretty cool.
>
> Let's move forward with this.
>
> bearophile's example uses `_` as a placeholder, but I don't see it
> mentioned in the rest of the DIP?
> ...
He had used it as a placeholder by convention, but it's just a valid
identifier. It would not be possible to use it for two distinct
variables in the same scope.
I.e., you can do:
```d
int _ = 2;
```
But not:
```d
int _ = 3;
int _ = 4;
```
Which would work with a true placeholder.
> For the example:
> ```
> auto arr = [tuple(1, "2"), tuple(3, "4"), tuple(5, "6")];
>
> foreach((x, y); arr) {
> writeln(x, " ", y); // "1 2\n3 4\n5 6"
> }
>
> foreach((int x, string y); arr) {
> writeln(x, " ", y);// "1 2\n3 4\n5 6"
> }
> ```
>
> shouldn't there be a trailing \n after the 6?
Yes.
More information about the dip.development
mailing list