Should we make it a requirement to include the parenthesis when unpacking tuples in for loops? This will in turn allow for this to work:
iterator foo(): tuple[x: tuple[y, z:int], y: tuple[y, z: int]] =
yield ((1, 2), (3, 4))
for ((a, b), (c, d)) in foo():
echo a, c
And be consistent with tuple unpacking in var/let declarations.
I consider this uglier than what we have currently, for example for
for (i, x) in @[1, 2,3]: ...
I don't consider that ugly.
That will break a LOT of code, time for 2to3-style? I like the new syntax though.
We can allow both I guess.
And deprecate the old one? Not sure how to implement the deprecation in the parser, but it should be possible. And I currently don't see a problem with syntax ambiguities either.
Superseded by #7486 (more comments and discussion there).
@narimiran
I think both these issues are different.
This issue is asking for nested tuple unpacking.
But that is not supported anywhere
var ((a, b), (c, d)) = ((1,2), (3,4)) # Parsing error
So this is kind of asking for general pattern matching support which as per Araq's opinion should be written as a macro. So this RFC has very less chances of being accepted anyways.
@nc-x So your solution doesn't work for the nested tuples? Can you make it work? :)
No, my patch doesn't support nested tuple unpacking. I didn't add it because the language does not support nested tuple unpacking anywhere. IDK if araq wants them in the language.
@narimiran So your best bet would be to convince @Araq ;)
PRs for nested tuple unpacking will be accepted.
Most helpful comment
PRs for nested tuple unpacking will be accepted.