-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove block argument from loop
#6026
Conversation
Wow, the counter var was never actually used in the compiler and stdlib? |
@straight-shoota i didn't even realise |
In the event anyone wants this feature back, I've put together a shard to replace this functionality. When the compiler eventually raises an exception on integer overflows, I'll patch my shard to handle that accordingly. Sidenote: the ability for me to bring a small feature like this back is one of my favorite features of Crystal! 😄 |
@Willamin I don't think this is helpful. That behaviour was removed for a reason. If you want to use a short cut to have looping block with an incrementing counter, it should have a different name at least.
What would that be? If there was a way to deal with that which would work for every use case, it could've stayed in the stdlib implementation. |
and do what? reset back to 0? That's even worse than raising! |
Introducing a block argument here was a mistake. Some people now want the loop index to be a different value. But the worse thing is that the loop index can silently overflow. And if we ever change the language to raise on overflow, this could eventually break some long running programs like servers (and that wouldn't be nice).
loop
is intended to be a cute syntax sugar forwhile true
while also allowing you to keep the variable inside the loop local to the block.Closes #5975