-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Don't skip nil result in loop expression, breaking change #66
Comments
I personally don't have too much loops to update yet :] but i think it's worth it anyway |
I've used/exploited the fact that nils don't get added in for loops before, and I approve this change. Being able to do either using continue is better than the current inability to add nils, in my opinion. One thing to consider might be whether list2 = for x in *list1 ought to be interpreted as list2 = for x in *list1 or list2 = for x in *list1 I think it's very reasonable that "else nil" should add the nils to the array. What's less clear, to me, is whether no else clause ought to add a nil to the list (are there any other situations where you can get an implicit nil result? I'm not recalling any off the top of my head, but it's late.) I'll probably have to spend a bit of time going through old loops to catch these, but I think this change is worth it. One thing that Lua got right, in my opinion, is the acceptance of making breaking changes. I think if you split languages into categories of "wants backwards compatibility" and "wants to improve the language at the expense of backcompat", you'll find much nicer languages in the second list. Also, Moonscript is new, don't be afraid to make breaking changes if they're for the better. I want to see this language grow. |
done many years ago and I never looked back! |
👍 |
Currently, if you assign a loop to something, or treat it as an expression the result of each iteration is accumulated into an array.
This is very similar to comprehensions, but if the result of an iteration is
nil
then it is not added to the array.This makes something like this possible:
The obvious downside is that these two things are not the same thing:
Since making this decision I've added the
continue
statement. It works with loop expressions, so thenil
check can be done explicitly:I think it's better to be explicit in cases like this. Therefore I plan to remove this
nil
check in the loop format.This is a backwards incompatible change. I've been going through some of my old code and it's kind of annoying finding instances of loops that need to be updated. That's why I'd like some feedback. Maybe this change is not worth it.
The text was updated successfully, but these errors were encountered: