tuple-syntax

Lance Bachmeier no at spam.net
Tue Mar 19 14:06:21 UTC 2024


On Tuesday, 19 March 2024 at 10:04:06 UTC, Dom DiSc wrote:
> On Monday, 18 March 2024 at 23:52:22 UTC, Basile B. wrote:
>> 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 ...
>>
>> That works but I dont like that. In my opinion that would be a 
>> case where the syntax would serve as a hint for the semantic 
>> analysis. That does not break the principle of "context-free 
>> grammar" however; just a bit odd to me.
>>
>> What about a property. Just `.tupleof`
> [...]
> ::lots of other proposals by others::
> [...]
>
> Most of these were discussed in the talk, and all have cases 
> where they become ambiguous or require new keywords / long 
> syntax.
> What I like about the trailing comma is that it's short, no new 
> keyword, and always unambiguous.
> Of course you could replace the comma by any other unused 
> symbol ('EOT' or '-' are bad ideas as the one is a new keyword 
> and the other produces some ambiguous cases, but we could use ' 
> or : or $ or whatever), but why?
> Comma is an obvious choice and much less ugly than most of what 
> I've seen else.

The comma is used as a separator. A trailing comma isn't used 
that way, so it looks weird to me. The spec says, "void has no 
value", so we already have a way to represent something that 
doesn't have a value: `(void)` and `(1, void)`. Although that's 
more verbose, I'm not convinced there's enough benefit to warrant 
the introduction of new syntax.


More information about the Digitalmars-d mailing list