A Discussion of Tuple Syntax

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Aug 21 09:25:30 PDT 2013


On 8/20/13 6:38 PM, Kenji Hara wrote:
> 2013/8/21 Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org
> <mailto:SeeWebsiteForEmail at erdani.org>>
>
>     I think this whole thread is approaching things wrongly. It should be:
>
>     1. What do we need?
>
>
> Both
> a. Built-in tuple construction syntax
> and
> b. Built-in tuple deconstruction syntax
>
>     2. What does a solution look like in the current language?
>
>
> a.
>    alias Types = {int, long};
>    auto values = {1, "str"};
> b.
>    auto {a, b} = tup;  // on variable declaration
>    {a, b} = tup;       // on assignment expression
>    ...

The current language would be D as it is today, with no syntactic 
addition. So I guess that would be:

a.
     alias Types = TypeTuple!(int, long);
     auto values = tuple(1, "str");
b.
     auto a = tup[0];
     auto b = tup[1];
     tup.scatter(a, b);

"scatter" is not defined yet. It scatters the content of a tuple over 
the (ref-passed) arguments.


Andrei




More information about the Digitalmars-d mailing list