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

De-implement looping over several elements per iteration #146

Closed
masak opened this issue Jun 12, 2016 · 0 comments
Closed

De-implement looping over several elements per iteration #146

masak opened this issue Jun 12, 2016 · 0 comments

Comments

@masak
Copy link
Owner

masak commented Jun 12, 2016

This currently works in 007:

$ bin/007 -e='for [1, 2, 3, 4] -> x, y { say(str(x) ~ " and " ~ str(y)) }'
1 and 2
3 and 4

I suggest we remove this feature. Naming a single variable as the loop variable will still be allowed.

Why? A couple of reasons:

  • The feature has not seen much use. In examples/ we currently have 3 for loops. All of them name one variable.
  • As we near v1.0, I'm getting increasingly aware of what features we're going to need to support long-term.
  • It's simpler code to do just one variable.
  • Making it 0-or-1 variables would make it identical to how the if statement works.
  • It's a smaller surface area to expose to APIs and the like to do just one variable.
  • There's the ever-present little glitch wherein if the elements don't come out even in the end, you get None for some of them. Not a big problem, just slightly inelegant.
  • The way I'd want this to work, on reflection, is using subsignature matching. Here's some hypothetical code: for [[1, 2], [3, 4]] -> [x, y] { say(str(x) ~ " and " ~ str(y)) }. Under something like Implement type checking, orthogonally to everything else #33, we could even get nice structural checking for that. We couldn't with the current implementation.

Lastly, .map doesn't do that trick in 007 (and I don't think it should):

$ bin/007 -e='[1, 2, 3, 4].map(sub (e1, e2) { say(e1 ~ " and " ~ e2) })'
Sub with 2 parameters called with 1 arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant