Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unpacking nested tuples in for loop #2436

Closed
dom96 opened this issue Mar 30, 2015 · 10 comments
Closed

Unpacking nested tuples in for loop #2436

dom96 opened this issue Mar 30, 2015 · 10 comments
Labels

Comments

@dom96
Copy link
Contributor

dom96 commented Mar 30, 2015

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.

@dom96 dom96 added the RFC label Mar 30, 2015
@def-
Copy link
Member

def- commented Mar 30, 2015

I consider this uglier than what we have currently, for example for

for (i, x) in @[1, 2,3]: ...

@dom96
Copy link
Contributor Author

dom96 commented Mar 30, 2015

I don't consider that ugly.

@reactormonk
Copy link
Contributor

That will break a LOT of code, time for 2to3-style? I like the new syntax though.

@dom96
Copy link
Contributor Author

dom96 commented Mar 30, 2015

We can allow both I guess.

@reactormonk
Copy link
Contributor

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.

@narimiran
Copy link
Member

Superseded by #7486 (more comments and discussion there).

@nc-x
Copy link
Contributor

nc-x commented Jan 2, 2019

@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.

@narimiran
Copy link
Member

@nc-x So your solution doesn't work for the nested tuples? Can you make it work? :)

@nc-x
Copy link
Contributor

nc-x commented Jan 2, 2019

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 ;)

@Araq
Copy link
Member

Araq commented Jan 3, 2019

PRs for nested tuple unpacking will be accepted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants