2013/3/29 Andrej Mitrovic <andrej.mitrovich@gmail.com>
On 3/29/13, kenji hara <k.hara.pg@gmail.com> wrote:
> http://wiki.dlang.org/DIP32
>
> Kenji Hara
>

<quote>
And, this syntax (currently it is not enough documented)
foreach (x, y; zip([1,2,3], ["a","b","c"])) {}
</quote>

Well that kinda sucks, I was just getting used to this syntax..But for
me it it was too magical to begin with, so I have no real complaints.

<quote>
if (auto {1, y} = tup) {
    // If the first element of tup (tup[0]) is equal to 1,
    // y captures the second element of tup (tup[1]).
}
</quote>

That looks like black magic to me.

<quote>
int x = 1;
if (auto {$x, y} = coord) { ... }
// If the first element of coord is equal to 1 (== x), 'then'
statement wil be evaluated.
</quote>

I really don't think we need this magic.. It feels like D and Perl had
lots of booze and made it to the mile-high club, and one of them got
pregnant.

I just thinks this adds way too many features at once. I'd argue we
should take it slow and start with some basic ability to define and
unpack tuples, and then gradually add these other features *if*
they're really wanted.

The new meaning of $ and $var and literals in if statements and "...",
is just too much for me to take.

I wrote about it to encourage discussions.

I can agree that $identifier looks weird, but a feature to do it is*necessary*.

When you create a pattern for matching, there is two cases.
- All value part can be represented by literal.
- Some values would be made in runtime.

bool testMatch(T)(int first_value, T tup) {
    if (auto {first_value, ...} = tup) { return true; } else { return false; }
    // first_value should be replaced to the given function argument, rather than capturing tup[0]
}
assert(testMatch(1, {1, 2, 3}) == true);
assert(testMatch(2, {1, 2, 3}) == false);

To distinct the capturing and evaluated value, var and $var is necessary.

Syntax for the feature is still debatable.

Kenji Hara