Implement for loops and array literals
#620
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For loops mostly use the Raku syntax (
->style), however since ourifandgivenall currently require parens around the condition or topic, we require them here too for consistency. We allow multiple loop variables for iterating two items at a time.For hashes, we do a key/value iteration, so you iterate the two at once and put them into separate variables. This isn't quite Perl or Raku, but it is the path of least resistance from what we have today to getting something useful. (We also don't go down the path of sigils beyond the existing
$.)Finally, array literals like
[1, 2]are also introduced. They can be used directly withforor assigned to a variable. There are no other operations on arrays for now; they are introduced primarily in support offor.An example just like the request in #600 is included among the tests, to make sure we can handle that use case.