A different tuple syntax
nazriel
spam at dzfl.pl
Thu May 30 20:07:15 PDT 2013
On Thursday, 30 May 2013 at 21:40:47 UTC, js.mdnq wrote:
> On Thursday, 30 May 2013 at 12:32:46 UTC, bearophile wrote:
>> If you don't like to introduce a new keyword, then a different
>> alternative is to use the @ again, a bit like UDAs:
>>
>> @{...}
>>
>> @[10] @{int, string} tup = @{1, "hi"}; // With UDA.
>> foreach (Float; @{float, double, real}) { ... }
>> auto @{x, y} = @{1, "hi"};
>> @{auto x, y} = @{1, "hi"};
>> @{int x, string y} = @{1, "hi"};
>> foreach (i, const @{x, y}; [@{1,2}, @{3,4}, @{5,6}, ...]) {
>> void foo(@{int, string name}, string msg);
>> (@{A a, B b}) => a + b;
>> switch (tup) { case @{1, 2}: ... }
>>
>> Bye,
>> bearophile
>
> Or rather # or & as they do have some inherent relation to
> tuples..
>
> #(int, string) tup
> &(int, string) tup
>
> The second remind one it is a sort of concatenation of types.
> e.g., int & string.
That actually looks good...
I liked idea of:
auto (x, y) = foo();
(int x1, string y1) = foo();
(int, string) foo() {
(int tmp, string tmp2) = (3, "dsa");
return (42, "dsa");
}
but it was shoot down because of various issues.
Then proposal with {} risen:
auto {x, y} = foo();
{int x1, string y1} = foo();
{int, string} foo() {
{int tmp, string tmp2} = {3, "dsa"};
return {42, "dsa"};
}
Now this:
auto #(x, y) = foo();
#(int x1, string y1) = foo();
#(int, string) foo() {
#(int tmp, string tmp2) = #(3, "dsa");
return #(42, "dsa");
}
I like eye-candies and the 1st syntax looks the best for me but
it won't happen.
Both 2nd example and 3rd proposed by js.mdnq looks good but IMHO
the 3rd is way more clear what is it about... also {} IMHO clash
a bit with our curly-bracket based language... it gets a bit
complicated where function begins, where if blocks begins and
where tuple declaration begins.
My 2 cents :))
bearophile what do you think?
More information about the Digitalmars-d
mailing list