Inverted syntax
Raku has statement modifiers:
Raku can also invert the syntax of loops:
Raku has a system of metaoperators that modify the characteristics of normal operators. Among these is the R
metaoperator, which is able to reverse the arguments of most infix operators (including user-defined ones).
So a reversed assignment is easy to write:
Since, much like list operators, assignment loosens the precedence of the following expression to allow comma lists, reverse assignment of a list requires parens where the normal assignment would not:
However, generally in that case you'd use a feed operator anyway, which is like an object pipe, but unlike Unix pipes works in either direction:
We think this is much more readable than a reversed assignment.
One other interesting inversion is the ability to put the conditional of a repeat loop at either end, with identical test-after semantics:
This might seem relatively useless, but it allows a variable to be declared in the conditional that isn't actually set until the loop body:
This would require a prior declaration (and two extra semicolons, horrors) if written in the non-inverted form with the conditional at the bottom:
You can't just put the my
on the $answer
in the block because the conditional is outside the scope of the block, and would not see the declaration.
Last updated