Inverted syntax: Difference between revisions

m
→‎{{header|Raku}}: fix a few old references to Perl 6
m (syntax highlighting fixup automation)
m (→‎{{header|Raku}}: fix a few old references to Perl 6)
Line 1,133:
=={{header|Raku}}==
(formerly Perl 6)
 
Like all Perls, Perl 6Raku has statement modifiers:
<syntaxhighlight lang="raku" line>if $guess == 6 { say "Wow! Lucky Guess!" } # Traditional
say 'Wow! Lucky Guess!' if $guess == 6; # Inverted
Line 1,139 ⟶ 1,140:
say 'Huh! You Guessed Rong!' unless $guess == 6; # Inverted</syntaxhighlight>
 
PerlRaku can also invertsinvert the syntax of loops:
<syntaxhighlight lang="raku" line>while $i { --$i }
--$i while $i;
Line 1,149 ⟶ 1,150:
.say if $_ %% 2 for 1..10; # list comprehension</syntaxhighlight>
 
Perl 6Raku has a system of metaoperators that modify the characteristics of normal operators. Among these is the <tt>R</tt> metaoperator, which is able to reverse the arguments of most infix operators (including user-defined ones).
So a reversed assignment is easy to write:
<syntaxhighlight lang="raku" line>42 R= $_; say $_; # prints 42</syntaxhighlight>
10,327

edits