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

Implement 'next' and 'last' #325

Closed
masak opened this issue Jun 28, 2018 · 4 comments · Fixed by #528
Closed

Implement 'next' and 'last' #325

masak opened this issue Jun 28, 2018 · 4 comments · Fixed by #528

Comments

@masak
Copy link
Owner

masak commented Jun 28, 2018

I'm not quite sure why we don't have them yet. I don't think they're all that difficult. We could probably emulate them with a control exception for now.

@masak
Copy link
Owner Author

masak commented Jul 13, 2018

And they probably need to be control flow exceptions anyway; see #145 (comment).

@masak
Copy link
Owner Author

masak commented Nov 20, 2018

Serious question: should (labeled) immediate blocks allow last? I find that surprising (an immediate block isn't a loop), but there's prior art: JavaScript does it that way.

What about other languages? Perl 5, Perl 6, Python, Java, C#, Ruby? I guess the landscape there can help determine what we do. If some of those languages don't allow breaking out of an immediate block, we might decide to follow suit. Using repeat while False (#160) to loop once seems more orthogonal anyway.

@masak
Copy link
Owner Author

masak commented Feb 17, 2019

  • Perl 6 and Java definitely forbid last/break outside of any loop or switch. I was able to confirm this by trying.
  • Perl 5 permits last in an immediate block. This, as far as I can tell, is because in Perl 5, an immediate block is a loop construct (so that the do ... while construct can work).
  • Python doesn't have immediate blocks. (Or, just in case it does and I'm just not seeing them, it still only allows break from directly inside of loops.)
  • I wasn't able to confirm either way with C# and Ruby.

...but on balance, I think we shouldn't do the last-from-immediate-block thing in 007. It's better to have simple, consistent rules.

@masak
Copy link
Owner Author

masak commented Feb 17, 2019

What I actually came into this issue to say is that I think we might as well do redo at the same time.

With redo too, there's the temptation to add it for not-loops. But (a) it actually changes the semantics, in case there's a nested block inside of the loop with a redo, and (b) it's more complicated, and sometimes simplicity is a virtue and generality is not.

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

Successfully merging a pull request may close this issue.

1 participant