Replies: 2 comments 1 reply
|
These proposals are good enhancements. You can go ahead with them.
FrançoiS
|
1 reply
|
Implemented in the March 2023 update, closing. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I'm pondering on implementing the following syntax enhancements:
Multiple when alternatives in case expressions
Allow more than one expression per case when alternative. Syntax would be identical to Ruby, eg.
Do-while loop
A standard loop with the condition at the end. Ruby's way of doing this requires the
ifmodifier we still don't have, and while I'd like to do it, I find in difficult to enhance the grammar this way. (Doesn't Ruby consider line endings when discerning if modifier from if statement? For us line endings are just whitespace.) So I propose the following syntax:loop whilebeing keywords. This adds a new keyword, and deviates from Ruby syntax.For each loop
We don't have arrays or collections, but the list for a for each loop could be efficiently hard-coded into the compiled code and it could be quite useful. It's true that Mindustry 7 lookup function allows to loop over built-in items, but this for each loop wouldn't quite identical. For example:
The compiled code would look something like this:
(Loop_start and loop_exit labels support the break and continue statements.) The list would accept expressions, which would be evaluated before the loop begins. It's defined in the Ruby's array syntax, which would make it's definition in grammar quite easy. Normal parentheses could be probably made to work too:
for unit in (@mono, @poly) ... end. I like this a wee bit more.Non-constant ranges
Like current ranges, but allowing expressions in the definition. Constant ranges would be still required for stack and heap allocations, but expression ranges could be used in for loops:
and case expressions:
@francois, if there's something you'd want to discuss beforehand, please let me know, otherwise I'd try to implement these enhancements (more or less in the given order).
All reactions