user
**Inverted syntax with conditional expressions**

In traditional syntax conditional expressions are usually shown before the action within a statement or code block:

```
 IF raining=true THEN needumbrella=true
```

In inverted syntax, the action is listed before the conditional expression in the statement or code block:

```
 needumbrella=true IF raining=true
```

**Inverted syntax with assignment**

In traditional syntax, assignments are usually expressed with the variable appearing before the expression:

```
 a = 6
```

In inverted syntax, the expression appears before the variable:

```
 6 = a
```

**Task**

The task is to demonstrate support for inverted syntax forms within the language by showing both the traditional and inverted forms.
assistant
(formerly Perl 6)

Raku has statement modifiers:

```
if $guess == 6 { say "Wow! Lucky Guess!" }          # Traditional
say 'Wow! Lucky Guess!' if $guess == 6;             # Inverted
unless $guess == 6 { say "Huh! You Guessed Rong!" } # Traditional
say 'Huh! You Guessed Rong!' unless $guess == 6;    # Inverted

```

Raku can also invert the syntax of loops:

```
while $i { --$i }
--$i while $i;

until $x > 10 { $x++ }
$x++ until $x > 10;

for 1..10 { .say if $_ %% 2 }
.say if $_ %% 2 for 1..10;  # list comprehension

```

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:

```
42 R= $_; say $_;   # prints 42

```

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:

```
my @a = 1,2,3;
(1,2,3) R= my @a;

```

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:

```
my @a <== 1,2,3;
1,2,3 ==> my @a;

```

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:

```
repeat {
    $_ = prompt "Gimme a number: ";
} until /^\d+$/;

repeat until /^\d+$/ {
    $_ = prompt "Gimme a number: ";
}

```

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:

```
repeat until my $answer ~~ 42 {
    $answer = prompt "Gimme an answer: ";
}

```

This would require a prior declaration (and two extra semicolons, horrors)
if written in the non-inverted form with the conditional at the bottom:

```
my $answer;
repeat {
    $answer = prompt "Gimme an answer: ";
} until $answer ~~ 42;

```

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.