tuple-syntax

Alexandru Ermicioi alexandru.ermicioi at gmail.com
Tue Mar 19 08:50:03 UTC 2024


On Sunday, 17 March 2024 at 20:20:52 UTC, Dom DiSc wrote:
> 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'd prefer typescript tuple syntax.
It's quite clear and concise:
```typescript
  const x: [int, double, named: triple];
```
I.e.
In d:
```d
const [int, double, named: triple] variable = [ 0, 0.0d, named: 
triple(1)];

const euto = [ 0, 0.0d, named: triple(1)];

static assert typeof(variable) == typeof(euto);

assert euto[0] == 0;
assert euto[1] == 0.0d;
assert euto[2] == triple(1);
assert euto.named == triple(1);
```

Best regards,
Alexandru


More information about the Digitalmars-d mailing list