Tuple literal syntax

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 6 23:41:50 PDT 2010


On Wednesday 06 October 2010 23:04:35 Walter Bright wrote:
> There have been a couple of looong threads about tuples:
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/Reddit_why_aren_t_peopl
> e_using_D_93528.html
> 
> http://www.digitalmars.com/d/archives/digitalmars/D/Should_the_comma_operat
> or_be_removed_in_D2_101321.html
> 
> A lot of it foundered on what the syntax for tuple literals should be. The
> top of the list is simply enclosing them in ( ). The problem with this is
> 
>   (expression)
> 
> Is that a parenthesized expression, or a tuple? This really matters, since
> (e)[0] means very different things for the two. Finally, I got to thinking,
> why not just make it a special case:
> 
> 
>   ( ) == tuple
>   (a) == parenthesized expression
>   (a,b) == tuple
>   (a,b,c) == tuple
>   (a,b,c,d) == tuple
> 
> etc.
> 
> No ambiguities! Only one special case. I submit this special case is rare,
> because who wants to define a function that returns a tuple of 1? Such will
> come about from generative programming, but:
> 
> (a,b,c)[0]
> 
> may be how the generative programming works, and that suggests:
> 
> (a,0)[0]
> 
> as how a user could generate a tuple of 1. Awkward, sure, but like I said,
> I think this would be rare.

As long as you can define () to use tuples in an unambiguous manner, I'm all for 
it. Personally, I don't really mind Tuple so much as I find the fact that you 
have both Tuple and TypeTuple to be highly confusing. But it wouldn't hurt my 
feelings to just use parens either.

- Jonathan M Davis


More information about the Digitalmars-d mailing list