## operators.md
## Chunk 1 of 6
Operators

Common Raku infixes, prefixes, postfixes, and more!

See [creating operators](/language/optut) on how to define new operators.

# [Operator precedence](#Operators "go to top of document")[§](#Operator_precedence "direct link")

The precedence and associativity of Raku operators determine the order of evaluation of operands in expressions.

Where two operators with a different precedence act on the same operand, the subexpression involving the higher-precedence operator is evaluated first. For instance, in the expression `1 + 2 * 3`, both the binary `+` operator for addition and the binary `*` operator for multiplication act on the operand `2`. Because the `*` operator has a higher precedence than the `+` operator, the subexpression `2 * 3` will be evaluated first. Consequently, the resulting value of the overall expression is `7` and not `9`.

Instead of "precedence" one can also speak of "binding": operators with a higher precedence are then said to have a tighter binding to the operand(s) in question, while operators with a lower precedence are said to have a looser binding. In practice one may also encounter blends of terminology, such as statements that an operator has a tighter or looser precedence.

The following table summarizes the precedence levels offered by Raku, listing them in order from high to low precedence. For each precedence level the table also indicates the associativity (discussed more below) of the operators assigned to that level and lists some example operators at that precedence level.

| Precedence Level | Associativity | Examples |
| --- | --- | --- |
| Term¹ | non | 42 3.14 "eek" qq["foo"] $x :!verbose @$array rand time now ∅ |
| Method call | left | .meth .+ .? .\* .() .[] .{} .<> .«» .:: .= .^ .: i |
| Autoincrement | non | ++ -- |
| Exponentiation | right | \*\* |
| Symbolic unary | left | ! + - ~ ? | || +^ ~^ ?^ ^ // |
| Dotty infix¹ | left | .= . |
| Multiplicative | left | \* × / ÷ % %% +& +< +> ~& ~< ~> ?& div mod gcd lcm |
| Additive | left | + - − +| +^ ~| ~^ ?| ?^ |
| Replication | left | x xx |
| Concatenation | list | ~ o ∘ |
| Junctive and | list | & (&) (.) ∩ ⊍ |
| Junctive or | list | | ^ (|) (^) (+) (-) ∪ ⊖ ⊎ ∖ |
| Named unary¹ | left | temp let |
| Structural | non | but does <=> leg unicmp cmp coll .. ..^ ^.. ^..^ |
| Chaining | chain | != ≠ == ⩵ < <= ≤ > >= ≥ eq ne lt le gt ge ~~ === ⩶ eqv !eqv =~= ≅ (elem) (cont) (<) (>) (<=) (>=) (<+) (>+) (==) ∈ ∊ ∉ ∋ ∍ ∌ ≡ ≢ ⊂ ⊄ ⊃ ⊅ ⊆ ⊈ ⊇ ⊉ ≼ ≽ |
| Tight and | list | && |
| Tight or | list | || ^^ // min max |
| Conditional¹ | right | ?? !! ff ff^ ^ff ^ff^ fff fff^ ^fff ^fff^ |
| Item assignment | right | =² => += -= \*\*= xx= |
| Loose unary | left | so not |
| Comma | list | , : |
| List infix | list | Z minmax X X~ X\* Xeqv ... … ...^ …^ ^... ^… ^...^ ^…^ |
| List prefix | right | =³ ??? !!! ... [+] [\*] Z= |
| Loose and | list | and andthen notandthen |
| Loose or | list | or xor orelse |
| Sequencer¹ | list | <== ==> <<== ==>> |
| Terminator¹ | non | ; {...} unless extra ) ] } |

Notes:

* for the precedence levels marked with `¹`, there are no operator subroutines with that precedence level (usually because the operators at that precedence level are special-cased by the compiler). This means that you cannot access that precedence level when setting the [precedence of custom operators](/language/functions#Precedence).
* `=²` denotes [item assignment](#infix_=_(item_assignment)) while `=³` denotes [list assignment operator](#infix_=_(list_assignment)).

# [Operator associativity](#Operators "go to top of document")[§](#Operator_associativity "direct link")

Where two operators with a same precedence level act on an operand, the associativity of the operators determines which subexpression/operator is evaluated first. For instance, in the expression `100 / 2 * 10`, the binary division operator `/` and the binary multiplication operator `*` have equal precedence, so that the order of their evaluation is determined by their associativity. As the two operators are *left associative*, operations are grouped from the left like this: `(100 / 2) * 10`. The expression thus evaluates to `500`. Conversely, if `/` and `*` had both been *right associative*, the expression would have been grouped as `100 / (2 * 10)` and would have evaluated to `5`.

The following table shows how each associativity affects the interpretation of an expression involving three such operators of equal precedence and the same associativity (using a fictitious infix `§` operator):

| Associativity | Meaning of $a § $b § $c § $d |
| --- | --- |
| left | (($a § $b) § $c) § $d |
| right | $a § ($b § ($c § $d)) |
| non | ILLEGAL |
| chain | ($a § $b) and ($b § $c) and ($c § $d) |
| list | infix:<§>($a, $b, $c, $d) |

Although this table only depicts infix operators, associativity also determines the order of evaluation for expressions with other types of operators. For example, if you created an infix `§` operator with the precedence `equiv(&prefix:<~>)`, then the order of evaluation of `~$a § $b` would depend on what associativity you assigned to `§`. If `§` is left associative, then `~$a` will be evaluated first and then passed to `§`; if `§` is right associative, then `$a § $b` will be evaluated first and passed to `~`.

When two operators have the same precedence but *different* associativity, determining the grouping of operands is more complicated. However, for operators built in to Raku, all operators with the same precedence level also have the same associativity.

Setting the associativity of non-infix operators is not yet implemented.

In the operator descriptions below, a default associativity of *left* is assumed.

# [Operator classification](#Operators "go to top of document")[§](#Operator_classification "direct link")

Operators can occur in several positions relative to a term:

|  |  |
| --- | --- |
| +term | prefix |
| term1 + term2 | infix |
| term++ | postfix |
| (term) | circumfix |
| term1[term2] | postcircumfix |
| .+(term) | method |

Each operator (except method operators) is also available as a subroutine. The name of the routine is formed from the operator category, followed by a colon, then a list quote construct with the symbol(s) that make up the operator:

```raku
infix:<+>(1, 2);                # same as 1 + 2
circumfix:«[ ]»(<a b c>);       # same as [<a b c>]
```

As a special case, a *listop* (list operator) can stand either as a term or as a prefix. Subroutine calls are the most common listops. Other cases include metareduced infix operators (`[+] 1, 2, 3`) and the [listop ...](#listop_...) etc. stub operators.

Defining custom operators is covered in [Defining operators functions](/language/functions#Defining_operators).

# [Substitution operators](#Operators "go to top of document")[§](#Substitution_operators "direct link")

Each substitution operator comes into two main forms: a lowercase one (e.g., `s///`) that performs *in-place* (i.e., *destructive* behavior; and an uppercase form (e.g., `S///`) that provides a *non-destructive* behavior.

## [`s///` in-place substitution](#Operators "go to top of document")[§](#s///_in-place_substitution "direct link")

```raku
my $str = 'old string';
$str ~~ s/o .+ d/new/;
say $str; # OUTPUT: «new string␤»
```

`s///` operates on the `$_` topical variable, changing it in place. It uses the given [`Regex`](/type/Regex) to find portions to replace and changes them to the provided replacement string. Sets `$/` to the [`Match`](/type/Match) object or, if multiple matches were made, a [`List`](/type/List) of [`Match`](/type/Match) objects. Returns `$/`.

It's common to use this operator with the `~~` smartmatch operator, as it aliases left-hand side to `$_`, which `s///` uses.

Regex captures can be referenced in the replacement part; it takes the same adverbs as the [`.subst` method](/routine/subst), which go between the `s` and the opening `/`, separated with optional whitespace:

```raku
my $str = 'foo muCKed into the lEn';

# replace second 'o' with 'x'
$str ~~ s:2nd/o/x/;

# replace 'M' or 'L' followed by non-whitespace stuff with 'd'
# and lowercased version of that stuff:
$str ~~ s :g :i/<[ML]> (\S+)/d{lc $0}/;

say $str; # OUTPUT: «fox ducked into the den␤»
```

You can also use a different delimiter:

```raku
my $str = 'foober';
$str ~~ s!foo!fox!;
$str ~~ s{b(.)r} = " d$0n";
say $str; # OUTPUT: «fox den␤»
```

Non-paired characters can simply replace the original slashes. Paired characters, like curly braces, are used only on the match portion, with the substitution given by assignment (of anything: a string, a routine call, etc.).

## [`S///` non-destructive substitution](#Operators "go to top of document")[§](#S///_non-destructive_substitution "direct link")

```raku
say S/o .+ d/new/ with 'old string';      # OUTPUT: «new string␤»
S:g/« (.)/$0.uc()/.say for <foo bar ber>; # OUTPUT: «Foo␤Bar␤Ber␤»
```

`S///` uses the same semantics as the `s///` operator, except it leaves the original string intact and *returns the resultant string* instead of `$/` (`$/` still being set to the same values as with `s///`).

**Note:** since the result is obtained as a return value, using this operator with the `~~` smartmatch operator is a mistake and will issue a warning. To execute the substitution on a variable that isn't the `$_` this operator uses, alias it to `$_` with `given`, `with`, or any other way. Alternatively, use the [`.subst` method](/routine/subst).

## [`tr///` in-place transliteration](#Operators "go to top of document")[§](#tr///_in-place_transliteration "direct link")

```raku
my $str = 'old string';
$str ~~ tr/dol/wne/;
say $str; # OUTPUT: «new string␤»
```

`tr///` operates on the `$_` topical variable and changes it in place. It behaves similar to [`Str.trans`](/routine/trans) called with a single [`Pair`](/type/Pair) argument, where key is the matching part (characters `dol` in the example above) and value is the replacement part (characters `wne` in the example above). Accepts the same adverbs as [`Str.trans`](/routine/trans). Returns the [`StrDistance`](/type/StrDistance) object that measures the distance between original value and the resultant string.

```raku
my $str = 'old string';
$str ~~ tr:c:d/dol st//;
say $str; # OUTPUT: «old st␤»
```

## [`TR///` non-destructive transliteration](#Operators "go to top of document")[§](#TR///_non-destructive_transliteration "direct link")

```raku
with 'old string' {
    say TR/dol/wne/; # OUTPUT: «new string␤»
}
```

`TR///` behaves the same as the `tr///` operator, except that it leaves the `$_` value untouched and instead returns the resultant string.

```raku
say TR:d/dol // with 'old string'; # OUTPUT: «string␤»
```

# [Assignment operators](#Operators "go to top of document")[§](#Assignment_operators "direct link")

Raku has a variety of assignment operators, which can be roughly classified as simple assignment operators and compound assignment operators.

The simple assignment operator symbol is `=`. It is 'overloaded' in the sense that it can mean either [item assignment](#infix_=_(item_assignment)) or [list assignment](#infix_=_(list_assignment)) depending on the context in which it is used:

```raku
my $x = 1;        # item assignment; $x = 1
my @x = 1,2,3;    # list assignment; @x = [1,2,3]
```

See the section on [item and list assignment](/language/variables#Item_and_list_assignment) for a more elaborate and comparative discussion of these two types of assignment.

The compound assignment operators are [metaoperators](#Metaoperators): they combine the simple assignment operator `=` with an infix operator to form a new operator that performs the operation specified by the infix operator before assigning the result to the left operand. Some examples of built-in compound assignment operators are `+=`, `-=`, `*=`, `/=`, `min=`, and `~=`. Here is how they work:

```raku
my $a = 32;
$a += 10;         # $a = 42
$a -= 2;          # $a = 40

$a = 3;
$a min= 5;        # $a = 3
$a min= 2;        # $a = 2

my $s = 'a';
$s ~= 'b';        # $s = 'ab'

# And an example of a custom operator:
sub infix:<space-concat> ($a, $b) { $a ~ " " ~ $b };
$a = 'word1';
$a space-concat= 'word2';                 # OUTPUT: «'word1 word2'␤»
```

One thing the simple and compound assignment operators have in common is that they form so-called *assignment expressions* that return or evaluate to the assigned value:

```raku
my sub fac (Int $n) { [*] 1..$n };        # sub for calculating factorial
my @x = ( my $y = fac(100), $y*101 );     # @x = [100!, 101!]

my $i = 0;
repeat { say $i } while ($i += 1) < 10;   # OUTPUT: «0,1,2,...9␤»
```

In the first example, the assignment expression `my $y = fac(100)` declares `$y`, assigns the value `fac(100)` to it, and finally returns the assigned value `fac(100)`. The returned value is then taken into account for constructing the List. In the second example the compound-assignment expression `$i += 1` assigns the value `$i + 1` to `$i`, and subsequently evaluates to the assigned value `$i+1`, thus allowing the returned value to be used for judging the while loop condition.

In dealing with simple and compound assignment operators, it is tempting to think that for instance the following two statements are (always) equivalent:

｢pseudo｣ without highlighting

```

```

expression1 += expression2;                     # compound assignment
expression1  = expression1 + expression2;       # simple assignment

```

```

They are not, however, for two reasons. Firstly, `expression1` in the compound assignment statement is evaluated only once, whereas `expression1` in the simple assignment statement is evaluated twice. Secondly, the compound assignment statement may, depending on the infix operator in question, implicitly initialize `expression1` if it is a variable with an undefined value. Such initialization will not occur for `expression1` in the simple assignment statement.

The aforementioned two differences between the simple and compound assignment statements are briefly elucidated below.

The first difference is common amongst programming languages and mostly self-explanatory. In the compound assignment, there is only one `expression1` that is explicitly specified to serve both as a term of the addition to be performed and as the location where the result of the addition, the sum, is to be stored. There is thus no need to evaluate it twice. The simple assignment, in contrast, is more generic in the sense that the value of the `expression1` that serves as a term of the addition need not necessarily be the same as the value of the `expression1` that defines the location where the sum must be stored. The two expressions are therefore evaluated separately. The distinction is particularly relevant in cases where the evaluation of `expression1` has side effects in the form of changes to one or more variables:

```raku
my @arr = [10, 20, 30];
my $i = 0;

if rand < 1/2 {
    @arr[++$i] += 1;                # @arr = [10,21,30]
} else {
    @arr[++$i] = @arr[++$i] + 1;    # @arr = [10,31,30] (or [10,20,21]?)
}                                   # the result may be implementation-specific
say @arr;
```

The second difference pointed out above is related to the widespread practice of using compound assignment operators in *accumulator patterns*. Such patterns involve a so-called *accumulator*: a variable that calculates the sum or a product of a series of values in a loop. To obviate the need for explicit accumulator initialization, Raku's compound assignment operators silently take care of the initialization where this is sensibly possible:

```raku
my @str = "Cleanliness is next to godliness".comb;
my ($len, $str);
for @str -> $c {
  $len += 1;
  $str ~= $c;
}
say "The string '$str' has $len characters.";
```

In this example the accumulators `$len` and `$str` are implicitly initialized to `0` and `""`, respectively, which illustrates that the initialization value is operator-specific. In this regard it is also noted that not all compound assignment operators can sensibly initialize an undefined left-hand side variable. The `/=` operator, for instance, will not arbitrarily select a value for the dividend; instead, it will throw an exception.

Although not strictly operators, methods can be used in the same fashion as compound assignment operators:

```raku
my $a = 3.14;
$a .= round;      # $a = $a.round; OUTPUT: «3»
```

# [Metaoperators](#Operators "go to top of document")[§](#Metaoperators "direct link")

Metaoperators can be parameterized with other operators or subroutines in the same way as functions can take other functions as parameters. To use a subroutine as a parameter, prefix its name with an `&`. Raku will generate the actual combined operator in the background, allowing the mechanism to be applied to user defined operators. To disambiguate chained metaoperators, enclose the inner operator in square brackets. There are quite a few metaoperators with different semantics as explained, next.

## [Negated relational operators](#Operators "go to top of document")[§](#Negated_relational_operators "direct link")

The result of a relational operator returning [`Bool`](/type/Bool) can be negated by prefixing with `!`. To avoid visual confusion with the `!!` operator, you may not modify any operator already beginning with `!`.

There are shortcuts for `!==` and `!eq`, namely `!=` and `ne`.

```raku
my $a = True;
say so $a != True;    # OUTPUT: «False␤»

my $release = Date.new(:2015year, :12month, :24day);
my $today = Date.today;
say so $release !before $today;     # OUTPUT: «False␤»
```

## [Reversed operators](#Operators "go to top of document")[§](#Reversed_operators "direct link")

Any infix operator may be called with its two arguments reversed by prefixing with `R`. Associativity of operands is reversed as well.

```raku
say 4 R/ 12;               # OUTPUT: «3␤»
say [R/] 2, 4, 16;         # OUTPUT: «2␤»
say [RZ~] <1 2 3>,<4 5 6>  # OUTPUT: «(41 52 63)␤»
```

## [Hyper operators](#Operators "go to top of document")[§](#Hyper_operators "direct link")

Hyper operators include `«` and `»`, with their ASCII variants `<<` and `>>`. They apply a given operator enclosed (or preceded or followed, in the case of unary operators) by `«` and/or `»` to one or two lists, returning the resulting list, with the pointy part of `«` or `»` aimed at the shorter list. Single elements are turned to a list, so they can be used too. If one of the lists is shorter than the other, the operator will cycle over the shorter list until all elements of the longer list are processed.

```raku
say (1, 2, 3) »*» 2;          # OUTPUT: «(2 4 6)␤»
say (1, 2, 3, 4) »~» <a b>;   # OUTPUT: «(1a 2b 3a 4b)␤»
say (1, 2, 3) »+« (4, 5, 6);  # OUTPUT: «(5 7 9)␤»
say (&sin, &cos, &sqrt)».(0.5);
# OUTPUT: «(0.479425538604203 0.877582561890373 0.707106781186548)␤»
```

The last example illustrates how postcircumfix operators (in this case .()) can also be hypered.

```raku
my @a = <1 2 3>;
my @b = <4 5 6>;
say (@a,@b)»[1]; # OUTPUT: «(2 5)␤»
```

In this case, it's the [postcircumfix[]](#circumfix_[_]) which is being hypered.

Assignment metaoperators can be *hyped*.

```raku
my @a = 1, 2, 3;
say @a »+=» 1;    # OUTPUT: «[2 3 4]␤»
my ($a, $b, $c);
(($a, $b), $c) «=» ((1, 2), 3);
say "$a, $c";       #  OUTPUT: «1, 3␤»
```

Hyper forms of unary operators have the pointy bit aimed at the operator and the blunt end at the list to be operated on.

```raku
my @wisdom = True, False, True;
say !« @wisdom;     # OUTPUT: «[False True False]␤»

my @a = 1, 2, 3;
@a»++;
say @a;             # OUTPUT: «[2 3 4]␤»
```

Hyper operators are defined recursively on nested arrays.

```raku
say -« [[1, 2], 3]; # OUTPUT: «[[-1 -2] -3]␤»
```

Also, methods can be called in an out of order, concurrent fashion. The resulting list will be in order. Note that all hyper operators are candidates for parallelism and will cause tears if the methods have side effects. The optimizer has full reign over hyper operators, which is the reason that they cannot be defined by the user.

```raku
class CarefulClass { method take-care {} }
my CarefulClass @objs;
my @results = @objs».take-care();

my @slops;        # May Contain Nuts
@slops».?this-method-may-not-exist();
```

Hyper operators can work with hashes. The pointy direction indicates if missing keys are to be ignored in the resulting hash. The enclosed operator operates on all values that have keys in both hashes.

|  |  |
| --- | --- |
| %foo «+» %bar; | intersection of keys |
| %foo »+« %bar; | union of keys |
| %outer »+» %inner; | only keys of %inner that exist in %outer will occur in the result |

```raku
my %outer = 1, 2, 3 Z=> <a b c>;
my %inner = 1, 2 Z=> <x z>;
say %outer «~» %inner;          # OUTPUT: «{"1" => "ax", "2" => "bz"}␤»
```

Hyper operators can take user-defined operators as their operator argument.

```raku
sub pretty-file-size (Int $size --> Str) {
    # rounding version of infix:</>(Int, Int)
    sub infix:<r/>(Int \i1, Int \i2) {
        round(i1 / i2, 0.1)
    }

    # we build a vector of fractions of $size and zip that with the fitting prefix
    for $size «[r/]« (2**60, 2**50, 2**40, 2**30, 2**20, 2**10)
              Z      <EB     PB     TB     GB     MB     KB> -> [\v,\suffix] {
        # starting with the biggest suffix,
        # we take the first that is 0.5 of that suffix or bigger
        return v ~ ' ' ~ suffix if v > 0.4
    }
    # this be smaller or equal then 0.4 KB
    return $size.Str;
}

for 60, 50, 40, 30, 20, 10 -> $test {
    my &a = { (2 ** $test) * (1/4, 1/2, 1, 10, 100).pick * (1..10).pick };
    print pretty-file-size(a.Int) xx 2, ' ';
}

# OUTPUT: «10 EB 4 EB 2 PB 5 PB 0.5 PB 4 TB 300 GB 4.5 GB 50 MB 200 MB 9 KB 0.6 MB␤»
```

Whether hyperoperators descend into child lists depends on the [nodality](/language/typesystem#trait_is_nodal) of the inner operator of a chain. For the hyper method call operator (».), the nodality of the target method is significant.

```raku
say (<a b>, <c d e>)».elems;        # OUTPUT: «(2 3)␤»
say (<a b>, <c d e>)».&{ .elems };  # OUTPUT: «((1 1) (1 1 1))␤»
```

You can chain hyper operators to destructure a List of Lists.

```raku
my $neighbors = ((-1, 0), (0, -1), (0, 1), (1, 0));
my $p = (2, 3);
say $neighbors »>>+<<» ($p, *);   # OUTPUT: «((1 3) (2 2) (2 4) (3 3))␤»
```

## [Reduction metaoperators](#Operators "go to top of document")[§](#Reduction_metaoperators "direct link")

The reduction metaoperator, `[ ]`, reduces a list with the given infix operator. It gives the same result as the [reduce](/routine/reduce) routine - see there for details.

```raku
# These two are equivalent:
say [+] 1, 2, 3;                # OUTPUT: «6␤»
say reduce &infix:<+>, 1, 2, 3; # OUTPUT: «6␤»
```

No whitespace is allowed between the square brackets and the operator. To wrap a function instead of an operator, provide an additional layer of square brackets:

```raku
sub plus { $^a + $^b };
say [[&plus]] 1, 2, 3;          # OUTPUT: «6␤»
```

The argument list is iterated without flattening. This means that you can pass a nested list to the reducing form of a list infix operator:

```raku
say [X~] (1, 2), <a b>;         # OUTPUT: «(1a 1b 2a 2b)␤»
```

which is equivalent to `1, 2 X~ <a b>`.

By default, only the final result of the reduction is returned. Prefix the wrapped operator with a `\`, to return a lazy list of all intermediate values instead. This is called a "triangular reduce". If the *non-meta* part contains a `\` already, quote it with `[]` (e.g. `[\[\x]]`).

```raku
my @n = [\~] 1..*;
say @n[^5];         # OUTPUT: «(1 12 123 1234 12345)␤»
```

## [Cross metaoperators](#Operators "go to top of document")[§](#Cross_metaoperators "direct link")

The cross metaoperator, `X`, will apply a given infix operator in order of cross product to all lists, such that the rightmost operand varies most quickly.

```raku
1..3 X~ <a b> # OUTPUT: «<1a, 1b, 2a, 2b, 3a, 3b>␤»
```

## [Zip metaoperator](#Operators "go to top of document")[§](#Zip_metaoperator "direct link")

The zip metaoperator (which is not the same thing as [Z](#infix_Z)) will apply a given infix operator to pairs taken one left, one right, from its arguments. The resulting list is returned.

```raku
my @l = <a b c> Z~ 1, 2, 3;     # OUTPUT: «[a1 b2 c3]␤»
```

If one of the operands runs out of elements prematurely, the zip operator will stop. An infinite list can be used to repeat elements. A list with a final element of `*` will repeat its 2nd last element indefinitely.

```raku
my @l = <a b c d> Z~ ':' xx *;  # OUTPUT: «<a: b: c: d:>»
   @l = <a b c d> Z~ 1, 2, *;   # OUTPUT: «<a1 b2 c2 d2>»
```

If an infix operator is not given, the `,` (comma operator) will be used by default:

```raku
my @l = 1 Z 2;  # OUTPUT: «[(1 2)]»
```

## [Sequential operators](#Operators "go to top of document")[§](#Sequential_operators "direct link")

The sequential metaoperator, `S`, will suppress any concurrency or reordering done by the optimizer. Most simple infix operators are supported.

```raku
say so 1 S& 2 S& 3;  # OUTPUT: «True␤»
```

## [Nesting of metaoperators](#Operators "go to top of document")[§](#Nesting_of_metaoperators "direct link")

To avoid ambiguity when chaining metaoperators, use square brackets to help the compiler understand you.

```raku
my @a = 1, 2, 3;
my @b = 5, 6, 7;
@a X[+=] @b;
say @a;         # OUTPUT: «[19 20 21]␤»
```

# [Term precedence](#Operators "go to top of document")[§](#Term_precedence "direct link")

## [term `< >`](#Operators "go to top of document")[§](#term_<_> "direct link")

The quote-words construct breaks up the contents on whitespace and returns a [`List`](/type/List) of the words. If a word looks like a number literal or a [`Pair`](/type/Pair) literal, it's converted to the appropriate number.

```raku
say <a b c>[1];   # OUTPUT: «b␤»
```

## [term `( )`](#Operators "go to top of document")[§](#term_(_) "direct link")

The grouping operator.

An empty group `()` creates an [empty list](/type/List#index-entry-()_(empty_list)). Parentheses around non-empty expressions simply structure the expression, but do not have additional semantics.

In an argument list, putting parenthesis around an argument prevents it from being interpreted as a named argument.

```raku
multi p(:$a!) { say 'named'      }
multi p($a)   { say 'positional' }
p a => 1;           # OUTPUT: «named␤»
p (a => 1);         # OUTPUT: «positional␤»
```

## [term `{ }`](#Operators "go to top of document")[§](#term_{_} "direct link")

[`Block`](/type/Block) or [`Hash`](/type/Hash) constructor.

If the content is empty, or contains a single list that starts with a [`Pair`](/type/Pair) literal or `%`-sigiled variable, and the [`$_` variable](/syntax/$_) or placeholder parameters are not used, the constructor returns a [`Hash`](/type/Hash). Otherwise it constructs a [`Block`](/type/Block).

To force construction of a [`Block`](/type/Block), follow the opening brace with a semicolon. To always ensure you end up with a [`Hash`](/type/Hash), you can use `%( )` coercer or [hash](/routine/hash) routine instead:

```raku
{}.^name.say;        # OUTPUT: «Hash␤»
{;}.^name.say;       # OUTPUT: «Block␤»

{:$_}.^name.say;     # OUTPUT: «Block␤»
%(:$_).^name.say;    # OUTPUT: «Hash␤»
hash(:$_).^name.say; # OUTPUT: «Hash␤»
```

## [circumfix `[ ]`](#Operators "go to top of document")[§](#circumfix_[_] "direct link")

The Array constructor returns an itemized [`Array`](/type/Array) that does not flatten in list context. Check this:

```raku
say .raku for [3,2,[1,0]]; # OUTPUT: «3␤2␤$[1, 0]␤»
```

This array is itemized, in the sense that every element constitutes an item, as shown by the `$` preceding the last element of the array, the [(list) item contextualizer](/type/Any#index-entry-%24_%28item_contextualizer%29).

# [Terms](#Operators "go to top of document")[§](#Terms "direct link")

Terms have their [own extended documentation](/language/terms).

# [Method postfix precedence](#Operators "go to top of document")[§](#Method_postfix_precedence "direct link")

## [postcircumfix `[ ]`](#Operators "go to top of document")[§](#postcircumfix_[_] "direct link")

```r


## operators.md
## Chunk 2 of 6
aku
sub postcircumfix:<[ ]>(@container, **@index,
                        :$k, :$v, :$kv, :$p, :$exists, :$delete)
```

Universal interface for positional access to zero or more elements of @container, a.k.a. "array indexing operator".

```raku
my @alphabet = 'a' .. 'z';
say @alphabet[0];                   # OUTPUT: «a␤»
say @alphabet[1];                   # OUTPUT: «b␤»
say @alphabet[*-1];                 # OUTPUT: «z␤»
say @alphabet[100]:exists;          # OUTPUT: «False␤»
say @alphabet[17, 0, 10, 20].join;  # OUTPUT: «raku␤»
say @alphabet[23 .. *].raku;        # OUTPUT: «("x", "y", "z")␤»

@alphabet[1, 2] = "B", "C";
say @alphabet[0..3].raku;           # OUTPUT: «("a", "B", "C", "d")␤»
```

See [Subscripts](/language/subscripts), for a more detailed explanation of this operator's behavior and for how to implement support for it in custom types.

## [postcircumfix `{ }`](#Operators "go to top of document")[§](#postcircumfix_{_} "direct link")

```raku
sub postcircumfix:<{ }>(%container, **@key,
                        :$k, :$v, :$kv, :$p, :$exists, :$delete)
```

Universal interface for associative access to zero or more elements of a %container, a.k.a. "hash indexing operator".

```raku
my %color = kiwi => "green", banana => "yellow", cherry => "red";
say %color{"banana"};                 # OUTPUT: «yellow␤»
say %color{"cherry", "kiwi"}.raku;    # OUTPUT: «("red", "green")␤»
say %color{"strawberry"}:exists;      # OUTPUT: «False␤»

%color{"banana", "lime"} = "yellowish", "green";
%color{"cherry"}:delete; # note that value is always returned but removal only happens when delete is true.
say %color;             # OUTPUT: «banana => yellowish, kiwi => green, lime => green␤»
```

See [`postcircumfix < >`](/language/operators#postcircumfix_<_>) and [`postcircumfix « »`](/routine/« »#(Operators)_postcircumfix_«_») for convenient shortcuts, and [Subscripts](/language/subscripts) for a more detailed explanation of this operator's behavior and how to implement support for it in custom types.

## [postcircumfix `<>`](#Operators "go to top of document")[§](#postcircumfix_<> "direct link")

Decontainerization operator, which extracts the value from a container and makes it independent of the container type.

```raku
use JSON::Tiny;

my $config = from-json('{ "files": 3, "path": "/home/some-user/raku.rakudoc" }');
say $config.raku;      # OUTPUT: «${:files(3), :path("/home/some-user/raku.rakudoc")}␤»
my %config-hash = $config<>;
say %config-hash.raku; # OUTPUT: «{:files(3), :path("/home/some-user/raku.rakudoc")}␤»

```

It's a [`Hash`](/type/Hash) in both cases, and it can be used like that; however, in the first case it was in item context, and in the second case it has been extracted to its proper context.

## [postcircumfix `< >`](#Operators "go to top of document")[§](#postcircumfix_<_> "direct link")

Shortcut for [`postcircumfix { }`](/routine/{ }#(Operators)_postcircumfix_{_}) that quotes its argument using the same rules as the [quote-words operator](#term_<_>) of the same name.

```raku
my %color = kiwi => "green", banana => "yellow", cherry => "red";
say %color<banana>;               # OUTPUT: «yellow␤»
say %color<cherry kiwi>.raku;     # OUTPUT: «("red", "green")␤»
say %color<strawberry>:exists;    # OUTPUT: «False␤»
```

Technically, not a real operator; it's syntactic sugar that's turned into the `{ }` postcircumfix operator at compile-time.

## [postcircumfix `« »`](#Operators "go to top of document")[§](#postcircumfix_«_» "direct link")

Shortcut for [`postcircumfix { }`](/routine/{ }#(Operators)_postcircumfix_{_}) that quotes its argument using the same rules as the [interpolating quote-words operator](/language/quoting#Word_quoting_with_interpolation_and_quote_protection:_«_») of the same name.

```raku
my %color = kiwi => "green", banana => "yellow", cherry => "red";
my $fruit = "kiwi";
say %color«cherry "$fruit"».raku;   # OUTPUT: «("red", "green")␤»
```

Technically, not a real operator; it's syntactic sugar that's turned into the `{ }` postcircumfix operator at compile-time.

## [postcircumfix `( )`](#Operators "go to top of document")[§](#postcircumfix_(_) "direct link")

The call operator treats the invocant as a [`Callable`](/type/Callable) and invokes it, using the expression between the parentheses as arguments.

Note that an identifier followed by a pair of parentheses is always parsed as a subroutine call.

If you want your objects to respond to the call operator, implement a [`method CALL-ME`](/routine/CALL-ME).

## [methodop `.`](#Operators "go to top of document")[§](#methodop_. "direct link")

The operator for calling one method, `$invocant.method`.

Technically, not a real operator; it's syntax special-cased in the compiler.

## [methodop `.&`](#Operators "go to top of document")[§](#methodop_.& "direct link")

The operator to call a [`Callable`](/type/Callable), such as a [`Block`](/type/Block), a [`Method`](/type/Method), or a [`Sub`](/type/Sub) with method syntax. The invocant will be bound to the first positional argument (and thus dispatch will fail if the [`Callable`](/type/Callable) does not accept at least one positional argument).

Technically, not a real operator; it's syntax special-cased in the compiler.

```raku
my sub f($invocant){ "The arg has a value of $invocant" }
42.&f;
# OUTPUT: «The arg has a value of 42␤»

42.&(-> $invocant { "The arg has a value of $invocant" });
# OUTPUT: «The arg has a value of 42␤»
```

## [methodop `.=`](#Operators "go to top of document")[§](#methodop_.= "direct link")

A mutating method call. `$invocant.=method` desugars to `$invocant = $invocant.method`, similar to [= (item assignment)](/routine/= (item assignment)) .

Technically, not a real operator; it's syntax special-cased in the compiler.

## [methodop `.^`](#Operators "go to top of document")[§](#methodop_.^ "direct link")

A metamethod call. `$invocant.^method` calls `method` on `$invocant`'s metaclass. It desugars to `$invocant.HOW.method($invocant, ...)`. See [the metaobject protocol documentation](/language/mop) for more information.

Technically, not a real operator; it's syntax special-cased in the compiler. It can be also applied, within classes, to access metamethods on self:

```raku
class Foo {
    has $.a = 3;
    method bar {
        return $.^name
    }
};
say Foo.new.bar; # OUTPUT: «Foo␤»

```

## [methodop `.?`](#Operators "go to top of document")[§](#methodop_.? "direct link")

Safe call operator. `$invocant.?method` calls method `method` on `$invocant` if it has a method of such name. Otherwise it returns [`Nil`](/type/Nil).

Technically, not a real operator; it's syntax special-cased in the compiler.

## [methodop `.+`](#Operators "go to top of document")[§](#methodop_.+ "direct link")

`$foo.+meth` walks the [MRO](/language/objects#index-entry-MRO) and calls all the methods called `meth` and submethods called `meth` if the type is the same as type of `$foo`. Those methods might be multis, in which case the matching candidate would be called.

After that, a [`List`](/type/List) of the results are returned. If no such method was found, it throws an [`X::Method::NotFound`](/type/X/Method/NotFound) exception.

```raku
class A {
  method foo { say "from A"; }
}
class B is A {
  multi method foo { say "from B"; }
  multi method foo(Str) { say "from B (Str)"; }
}
class C is B is A {
  multi method foo { say "from C"; }
  multi method foo(Str) { say "from C (Str)"; }
}

say C.+foo; # OUTPUT: «from C␤from B␤from A␤(True True True)␤»
```

## [methodop `.*`](#Operators "go to top of document")[§](#methodop_.* "direct link")

`$foo.*meth` walks the [MRO](/language/objects#index-entry-MRO) and calls all the methods called `meth` and submethods called `meth` if the type is the same as type of `$foo`. Those methods might be multis, in which case the matching candidate would be called.

After that, a [`List`](/type/List) of the results are returned. If no such method was found, an empty [`List`](/type/List) is returned.

Technically, postfix `.+` calls `.*` at first. Read postfix `.+` section to see examples.

## [methodop `».` / methodop `>>.`](#Operators "go to top of document")[§](#methodop_»._/_methodop_>>. "direct link")

This is the hyper method call operator. Will call a method on all elements of a [`List`](/type/List) out of order and return the list of return values in order.

```raku
my @a = <a b c>;
my @b = @a».ord;                  # OUTPUT: «[97, 98, 99]␤»
# The first parameter of a method is the invocant.
sub foo(Str:D $c){ $c.ord * 2 };
# So we can pretend to have a method call with a sub that got a good
# first positional argument.
say @a».&foo;
# Blocks have an implicit positional arguments that lands in $_. The latter can
# be omitted for method calls.
say @a».&{ .ord};

```

Hyper method calls may appear to be the same as doing a [map](/routine/map) call, however along with being a hint to the compiler that it can parallelize the call, the behavior is also affected by [nodality of the method](/routine/is%20nodal) being invoked, depending on which either [nodemap](/routine/nodemap) or [deepmap](/routine/deepmap) semantics are used to perform the call.

The nodality is checked by looking up whether the [`Callable`](/type/Callable) provides `nodal` method. If the hyper is applied to a method, that [`Callable`](/type/Callable) is that method name, looked up on [`List`](/type/List) type; if the hyper is applied to a routine (e.g. `».&foo`), that routine functions as that [`Callable`](/type/Callable). If the [`Callable`](/type/Callable) is determined to provide `nodal` method, [nodemap](/routine/nodemap) semantics are used to perform the hyper call, otherwise [duckmap](/routine/duckmap) semantics are used.

Take care to avoid a [common mistake](/language/traps#Using_»_and_map_interchangeably) of expecting side-effects to occur in order. The following `say` is **not** guaranteed to produce the output in order:

```raku
@a».say;  # WRONG! Could produce a␤b␤c␤ or c␤b␤a␤ or any other order

```

## [methodop `.postfix` / `.postcircumfix`](#Operators "go to top of document")[§](#methodop_.postfix_/_.postcircumfix "direct link")

In most cases, a dot may be placed before a postfix or postcircumfix:

```raku
my @a;
@a[1, 2, 3];
@a.[1, 2, 3]; # Same
```

This can be useful for visual clarity or brevity. For example, if an object's attribute is a function, putting a pair of parentheses after the attribute name will become part of the method call. So, either two pairs of parentheses must be used or a dot has to come before the parentheses to separate it from the method call.

```raku
class Operation {
    has $.symbol;
    has &.function;
}
my $addition = Operation.new(:symbol<+>, :function{ $^a + $^b });
say $addition.function()(1, 2);   # OUTPUT: «3␤»
# OR
say $addition.function.(1, 2);    # OUTPUT: «3␤»
```

If the postfix is an identifier, however, it will be interpreted as a normal method call.

```raku
1.i # No such method 'i' for invocant of type 'Int'

```

Technically, not a real operator; it's syntax special-cased in the compiler.

## [methodop `.:<prefix operator>`](#Operators "go to top of document")[§](#methodop_.:<prefix_operator> "direct link")

An operator in prefix form can still be called like a method, that is, using the `.` methodop notation, by preceding it by a colon. For example:

```raku
my $a = 1;
say ++$a;       # OUTPUT: «2␤»
say $a.:<++>;   # OUTPUT: «3␤»
```

Technically, not a real operator; it's syntax special-cased in the compiler, that is why it's classified as a *methodop*.

## [methodop `.::`](#Operators "go to top of document")[§](#methodop_.:: "direct link")

A class-qualified method call, used to call a method as defined in a parent class or role, even after it has been redefined in the child class.

```raku
class Bar {
    method baz { 42 }
}
class Foo is Bar {
    method baz { "nope" }
}
say Foo.Bar::baz;       # OUTPUT: «42␤»
```

## [postfix `,=`](#Operators "go to top of document")[§](#postfix_,= "direct link")

Creates an object that concatenates, in a class-dependent way, the contents of the variable on the left hand side and the expression on the right hand side:

```raku
my %a = :11a, :22b;
%a ,= :33x;
say %a # OUTPUT: «{a => 11, b => 22, x => 33}␤»
```

# [Autoincrement precedence](#Operators "go to top of document")[§](#Autoincrement_precedence "direct link")

## [`++`](#Operators "go to top of document")[§](#prefix_++ "direct link")

```raku
multi prefix:<++>($x is rw) is assoc<non>
```

Increments its argument by one and returns the updated value.

```raku
my $x = 3;
say ++$x;   # OUTPUT: «4␤»
say $x;     # OUTPUT: «4␤»
```

It works by calling the [succ](/routine/succ) method (for *successor*) on its argument, which gives custom types the freedom to implement their own increment semantics.

## [`--`](#Operators "go to top of document")[§](#prefix_-- "direct link")

```raku
multi prefix:<-->($x is rw) is assoc<non>
```

Decrements its argument by one and returns the updated value.

```raku
my $x = 3;
say --$x;   # OUTPUT: «2␤»
say $x;     # OUTPUT: «2␤»
```

It works by calling the [pred](/routine/pred) method (for *predecessor*) on its argument, which gives custom types the freedom to implement their own decrement semantics.

## [`++`](#Operators "go to top of document")[§](#postfix_++ "direct link")

```raku
multi postfix:<++>($x is rw) is assoc<non>
```

Increments its argument by one and returns the original value.

```raku
my $x = 3;
say $x++;   # OUTPUT: «3␤»
say $x;     # OUTPUT: «4␤»
```

It works by calling the [succ](/routine/succ) method (for *successor*) on its argument, which gives custom types the freedom to implement their own increment semantics; when undefined, it sets the value to 1 and returns it.

```raku
my $x;
$x++;
say $x;     # OUTPUT: «1␤»
```

Note that this does not necessarily return its argument; e.g., for undefined values, it returns 0:

```raku
my $x;
say $x++;   # OUTPUT: «0␤»
say $x;     # OUTPUT: «1␤»
```

Increment on [`Str`](/type/Str) will increment the number part of a string and assign the resulting string to the container. An `is rw` container is required.

```raku
my $filename = "somefile-001.txt";
say $filename++ for 1..3;
# OUTPUT: «somefile-001.txt␤somefile-002.txt␤somefile-003.txt␤»
```

This will act on any Unicode numeral:

```raku
my $was٧ = "ثمانية٧";
$was٧++;
say $was٧; # OUTPUT: «ثمانية٨␤»

```

Including, since version 6.d, Thai numerals

```raku
my $เลขไทย="๙๙";
$เลขไทย++;
say $เลขไทย; # OUTPUT: «๑๐๐␤»

```

## [`--`](#Operators "go to top of document")[§](#postfix_-- "direct link")

```raku
multi postfix:<-->($x is rw) is assoc<non>
```

Decrements its argument by one and returns the original value.

```raku
my $x = 3;
say $x--;   # OUTPUT: «3␤»
say $x;     # OUTPUT: «2␤»
```

It works by calling the [pred](/routine/pred) method (for *predecessor*) on its argument, which gives custom types the freedom to implement their own decrement semantics.

Note that this does not necessarily return its argument;e.g., for undefined values, it returns 0:

```raku
my $x;
say $x--;   # OUTPUT: «0␤»
say $x;     # OUTPUT: «-1␤»
```

Decrement on [`Str`](/type/Str) will decrement the number part of a string and assign the resulting string to the container. An `is rw` container is required. Crossing 0 is prohibited and throws [`X::AdHoc`](/type/X/AdHoc).

```raku
my $filename = "somefile-003.txt";
say $filename-- for 1..3;
# OUTPUT: «somefile-003.txt␤somefile-002.txt␤somefile-001.txt␤»
```

# [Exponentiation precedence](#Operators "go to top of document")[§](#Exponentiation_precedence "direct link")

## [infix `**`](#Operators "go to top of document")[§](#infix_** "direct link")

```raku
multi infix:<**>(Any, Any --> Numeric:D) is assoc<right>
```

The exponentiation operator coerces both arguments to [`Numeric`](/type/Numeric) and calculates the left-hand-side raised to the power of the right-hand side.

If the right-hand side is a non-negative integer and the left-hand side is an arbitrary precision type ([`Int`](/type/Int), [`FatRat`](/type/FatRat)), then the calculation is carried out without loss of precision.

Unicode superscripts will behave in exactly the same way.

```raku
sub squared( Int $num ) { $num² };
say squared($_) for ^5; # OUTPUT: «0␤1␤4␤9␤16␤»
```

It also works for sequences of several Unicode superscript numbers:

```raku
sub twenty-second-power( Int $num ) { $num²² };
say twenty-second-power($_) for ^5; # OUTPUT: «0␤1␤4194304␤31381059609␤17592186044416␤»
```

# [Symbolic unary precedence](#Operators "go to top of document")[§](#Symbolic_unary_precedence "direct link")

## [prefix `?`](#Operators "go to top of document")[§](#prefix_? "direct link")

```raku
multi prefix:<?>(Mu --> Bool:D)
```

Boolean context operator.

Coerces the argument to [`Bool`](/type/Bool) by calling the [`Bool`](/type/Bool) method on it. Note that this collapses [`Junction`](/type/Junction)s.

## [prefix `!`](#Operators "go to top of document")[§](#prefix_! "direct link")

```raku
multi prefix:<!>(Mu --> Bool:D)
```

Negated Boolean context operator.

Coerces the argument to [`Bool`](/type/Bool) by calling the [`Bool`](/type/Bool) method on it, and returns the negation of the result. Note that this collapses [`Junction`](/type/Junction)s.

## [prefix `//`](#Operators "go to top of document")[§](#prefix_// "direct link")

```raku
multi prefix:<//>(Any --> Bool:D)
```

Boolean context operator.

Available as of 6.e language version (early implementation exists in Rakudo compiler 2022.12+).

Coerces the argument to [`Boolean`](/type/Bool) by calling the `defined` method on it.

## [prefix `+`](#Operators "go to top of document")[§](#prefix_+ "direct link")

```raku
multi prefix:<+>(Any --> Numeric:D)
```

Numeric context operator.

Coerces the argument to [`Numeric`](/type/Numeric) by calling the `Numeric` method on it.

## [prefix `-`](#Operators "go to top of document")[§](#prefix_- "direct link")

```raku
multi prefix:<->(Any --> Numeric:D)
```

Negative numeric context operator.

Coerces the argument to [`Numeric`](/type/Numeric) by calling the `Numeric` method on it, and then negates the result.

## [prefix `~`](#Operators "go to top of document")[§](#prefix_~ "direct link")

```raku
multi prefix:<~>(Any --> Str:D)
```

String context operator.

Coerces the argument to [`Str`](/type/Str) by calling the [Str](/type/List#method_Str) method on it.

## [prefix `|`](#Operators "go to top of document")[§](#prefix_| "direct link")

Flattens objects of type [`Capture`](/type/Capture), [`Pair`](/type/Pair), [`List`](/type/List), [`Map`](/type/Map) and [`Hash`](/type/Hash) into an argument list.

```raku
sub slurpee( |args ){
    say args.raku
};
slurpee( <a b c d>, { e => 3 }, 'e' => 'f' => 33 )
# OUTPUT: «\(("a", "b", "c", "d"), {:e(3)}, :e(:f(33)))␤»
```

Please see the [signature literals page, specially the section on Captures](/language/signatures#Capture_parameters) for more information on the subject.

Outside of argument lists, it returns a [`Slip`](/type/Slip), which makes it flatten into the outer list. Inside [argument list](/language/list#Argument_list_(Capture)_context) [`Positional`s](/type/Positional) are turned into positional arguments and [`Associative`s](/type/Associative) are turned into named arguments.

## [prefix `+^`](#Operators "go to top of document")[§](#prefix_+^ "direct link")

```raku
multi prefix:<+^>(Any --> Int:D)
```

Integer bitwise negation operator: converts the number to binary using as many bytes as needed by the number plus one; flips all bits and returns the result assuming it is a [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) representation.

```raku
say +^255; # OUTPUT: «-256␤»

```

In this case, 255 is 11111111 and would need a single byte. We use the representation in bytes needed for this value plus one, converting it to 0000 0000 1111 1111. Bitwise negation turns it into 1111 1111 0000 0000 and this is the representation in two's complement of -256, which is returned.

```raku
say +^1;        # OUTPUT: «-2␤»
say +^(-256);   # OUTPUT: «255␤»

```

Negative numbers are assumed to be represented as two's complements, and thus circle back to the original number.

## [prefix `~^`](#Operators "go to top of document")[§](#prefix_~^ "direct link")

Coerces the argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then flips each bit in that buffer.

Please note that this has not yet been implemented.

## [prefix `?^`](#Operators "go to top of document")[§](#prefix_?^ "direct link")

```raku
multi prefix:<?^>(Mu --> Bool:D)
```

Boolean bitwise negation operator: Coerces the argument to [`Bool`](/type/Bool) and then does a bit flip, which makes it the same as `prefix:<!>`.

## [prefix `^`](#Operators "go to top of document")[§](#prefix_^ "direct link")

```raku
multi prefix:<^>(Any --> Range:D)
```

*upto* operator.

Coerces the argument to [`Numeric`](/type/Numeric), and generates a range from 0 up to (but excluding) the argument.

```raku
say ^5;         # OUTPUT: «0..^5␤»
for ^5 { }      # 5 iterations
```

# [Dotty infix precedence](#Operators "go to top of document")[§](#Dotty_infix_precedence "direct link")

These operators are like their Method Postfix counterparts, but require surrounding whitespace (before and/or after) to distinguish them.

## [infix `.=`](#Operators "go to top of document")[§](#infix_.= "direct link")

Calls the right-side method on the value in the left-side container, replacing the resulting value in the left-side container.

In most cases, this behaves identically to the postfix mutator, but the precedence is lower:

```raku
my $a = -5;
say ++$a.=abs;
# OUTPUT: «6␤»

```

```raku
say ++$a .= abs;
# OUTPUT: «Cannot modify an immutable Int␤
#           in block <unit> at <tmp> line 1␤␤»

```

## [infix `.`](#Operators "go to top of document")[§](#infix_. "direct link")

Calls the following method (whose name must be alphabetic) on the left-side invocant.

Note that the infix form of the operator has a slightly lower precedence than postfix `.meth`.

```raku
say -5.abs;      # like: -(5.abs)
# OUTPUT: «-5␤»
say -5 . abs;    # like: (-5) . abs
# OUTPUT: «5␤»
say -5 .abs;     # following whitespace is optional
# OUTPUT: «5␤»
```

# [Multiplicative precedence](#Operators "go to top of document")[§](#Multiplicative_precedence "direct link")

## [infix `*`](#Operators "go to top of document")[§](#infix_* "direct link")

```raku
multi infix:<*>(Any, Any --> Numeric:D)
```

Multiplication operator.

Coerces both arguments to [`Numeric`](/type/Numeric) and multiplies them. The result is of the wider type. See [`Numeric`](/type/Numeric) for details.

## [infix `/`](#Operators "go to top of document")[§](#infix_/ "direct link")

```raku
multi infix:</>(Any, Any --> Numeric:D)
```

Division operator.

Coerces both argument to [`Numeric`](/type/Numeric) and divides the left through the right number. Division of [`Int`](/type/Int) values returns [`Rat`](/type/Rat), otherwise the "wider type" rule described in [`Numeric`](/type/Numeric) holds.

Note there is also [`div`](#infix_div) for [`Int`](/type/Int) division.

## [infix `div`](#Operators "go to top of document")[§](#infix_div "direct link")

```raku
multi infix:<div>(Int:D, Int:D --> Int:D)
```

Integer division operator. Rounds down.

Note there is also [`/`](#infix_/) for [`Numeric`](/type/Numeric) division.

## [infix `%`](#Operators "go to top of document")[§](#infix_% "direct link")

```raku
multi infix:<%>($x, $y --> Numeric:D)
```

Modulo operator. Coerces to [`Numeric`](/type/Numeric) first.

Generally the following identity holds:

```raku
my ($x, $y) = 1,2;
$x % $y == $x - floor($x / $y) * $y
```

Note there is also [`mod`](#infix_%) for [`Int`](/type/Int) modulo.

## [infix `%%`](#Operators "go to top of document")[§](#infix_%% "direct link")

```raku
multi infix:<%%>($a, $b --> Bool:D)
```

Divisibility operator. Returns `True` if `$a % $b == 0`.

## [infix `mod`](#Operators "go to top of document")[§](#infix_mod "direct link")

```raku
multi infix:<mod>(Int:D $a, Int:D $b --> Int:D)
```

Integer modulo operator. Returns the remainder of an integer modulo operation.

Note there is also [`%`](#infix_%) for [`Numeric`](/type/Numeric) modulo.

## [infix `+&`](#Operators "go to top of document")[§](#infix_+& "direct link")

```raku
multi infix:<+&>($a, $b --> Int:D)
```

Numeric bitwise *AND* operator. Coerces both arguments to [`Int`](/type/Int) and does a bitwise *AND* operation assuming two's complement.

## [infix `+<`](#Operators "go to top of document")[§](#infix_+< "direct link")

```raku
multi infix:«+<»($a, $b --> Int:D)
```

Integer bit shift to the left.

## [infix `+>`](#Operators "go to top of document")[§](#infix_+> "direct link")

```raku
multi infix:«+>»($a, $b --> Int:D)
```

Integer bit shift to the right.

## [infix `~&`](#Operators "go to top of document")[§](#infix_~& "direct link")

Coerces each argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then performs a numeric bitwise AND on corresponding integers of the two buffers, padding the shorter buffer with zeroes.

## [infix `~<`](#Operators "go to top of document")[§](#infix_~< "direct link")

Coerces the left argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then performs a numeric bitwise left shift on the bits of the buffer.

Please note that this has not yet been implemented.

## [infix `~>`](#Operators "go to top of document")[§](#infix_~> "direct link")

Coerces the left argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then performs a numeric bitwise right shift on the bits of the buffer.

Please note that this has not yet been implemented.

## [infix `?&`](#Operators "go to top of document")[§](#infix_?& "direct link")

```raku
multi infix:<?&>(Mu $x = Bool::True)
multi infix:<?&>(Mu \a, Mu \b)
```

Boolean logical AND operator. Coerces the argument(s) to [`Bool`](/type/Bool) and performs logical AND on it(them): it will return True if and only if both arguments are True. On a single argument it behaves as identity, returning the coerced value.

## [infix `gcd`](#Operators "go to top of document")[§](#infix_gcd "direct link")

```raku
multi infix:<gcd>($a, $b --> Int:D)
```

Coerces both arguments to [`Int`](/type/Int) and returns the greatest common divisor. If one of its arguments is 0, the other is returned (when both arguments are 0, the operator returns 0).

## [infix `lcm`](#Operators "go to top of document")[§](#infix_lcm "direct link")

```raku
multi infix:<lcm>($a, $b --> Int:D)
```

Coerces both arguments to [`Int`](/type/Int) and returns the least common multiple; that is, the smallest integer that is evenly divisible by both arguments.

# [Additive precedence](#Operators "go to top of document")[§](#Additive_precedence "direct link")

## [infix `+`](#Operators "go to top of document")[§](#infix_+ "direct link")

```raku
multi infix:<+>($a, $b --> Numeric:D)
```

Addition operator: Coerces both arguments to [`Numeric`](/type/Numeric) and adds them. From version 6.d it works also on [`Duration`](/type/Duration), [`DateTime`](/type/DateTime) and [`Real`](/type/Real) types.

## [infix `-`](#Operators "go to top of document")[§](#infix_- "direct link")

```r


## operators.md
## Chunk 3 of 6
aku
multi infix:<->($a, $b --> Numeric:D)
```

Subtraction operator: Coerces both arguments to [`Numeric`](/type/Numeric) and subtracts the second from the first. From version 6.d it works also on [`Duration`](/type/Duration), [`DateTime`](/type/DateTime) and [`Real`](/type/Real) types.

## [infix `+|`](#Operators "go to top of document")[§](#infix_+| "direct link")

```raku
multi infix:<+|>($a, $b --> Int:D)
```

Integer bitwise OR operator: Coerces both arguments to [`Int`](/type/Int) and does a bitwise *OR* (inclusive OR) operation.

## [infix `+^`](#Operators "go to top of document")[§](#infix_+^ "direct link")

```raku
multi infix:<+^>($a, $b --> Int:D)
```

Integer bitwise XOR operator: Coerces both arguments to [`Int`](/type/Int) and does a bitwise *XOR* (exclusive OR) operation.

```raku
say (0b00001101 +^ 0b00001001).base(2); # OUTPUT: «100␤»

```

## [infix `~|`](#Operators "go to top of document")[§](#infix_~| "direct link")

Coerces each argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then performs a numeric bitwise OR on corresponding integers of the two buffers, padding the shorter buffer with zeroes.

## [infix `~^`](#Operators "go to top of document")[§](#infix_~^ "direct link")

Coerces each argument to a non-variable-encoding string buffer type (e.g. `buf8`, `buf16`, `buf32`) and then performs a numeric bitwise XOR on corresponding integers of the two buffers, padding the shorter buffer with zeroes.

## [infix `?^`](#Operators "go to top of document")[§](#infix_?^ "direct link")

```raku
multi infix:<?^>(Mu $x = Bool::False)
multi infix:<?^>(Mu \a, Mu \b)
```

Boolean logical XOR operator. Coerces the argument(s) to [`Bool`](/type/Bool) and performs logical XOR on it(them): it will return True if and only if just one of the argument is True. On a single argument it behaves as identity, returning the coerced value.

## [infix `?|`](#Operators "go to top of document")[§](#infix_?| "direct link")

```raku
multi infix:<?|>(Mu $x = Bool::False)
multi infix:<?|>(Mu \a, Mu \b)
```

Boolean logical OR operator. Coerces the argument(s) to [`Bool`](/type/Bool) and performs logical OR (inclusive OR) on it(them): it will return True if at least one of the argument is True. On a single argument it behaves as identity, returning the coerced value.

# [Replication precedence](#Operators "go to top of document")[§](#Replication_precedence "direct link")

## [infix `x`](#Operators "go to top of document")[§](#infix_x "direct link")

```raku
sub infix:<x>($a, $b --> Str:D)
```

String repetition operator.

Repeats the string `$a` `$b` times, if necessary coercing `$a` to [`Str`](/type/Str) and `$b` to [`Int`](/type/Int). Returns an empty string if `$b <= 0`. An exception `X::Numeric::CannotConvert` will be thrown if `$b` is `-Inf` or `NaN`.

```raku
say 'ab' x 3;           # OUTPUT: «ababab␤»
say 42 x 3;             # OUTPUT: «424242␤»

my $a = 'a'.IO;
my $b = 3.5;
say $a x $b;            # OUTPUT: «aaa␤»
```

## [infix `xx`](#Operators "go to top of document")[§](#infix_xx "direct link")

```raku
multi infix:<xx>()
multi infix:<xx>(Mu \x)
multi infix:<xx>(&x, Num:D() $n)
multi infix:<xx>(&x, Whatever)
multi infix:<xx>(&x, Bool:D $b)
multi infix:<xx>(&x, Int:D $n)
multi infix:<xx>(Mu \x, Num:D() $n)
multi infix:<xx>(Mu \x, Whatever)
multi infix:<xx>(Mu \x, Bool:D $b)
multi infix:<xx>(Mu \x, Int:D $n)
```

List repetition operator

In general, it returns a Sequence of `$a` repeated and evaluated `$b` times (`$b` is coerced to [`Int`](/type/Int)). If `$b <= 0`, the empty list is returned. It will return an error with no operand, and return the operand itself with a single operand. An exception [`X::Numeric::CannotConvert`](/type/X/Numeric/CannotConvert) will be thrown if `$b` is `-Inf` or `NaN`.

The left-hand side is evaluated for each repetition, so

```raku
say [1, 2] xx 5;
# OUTPUT: «([1 2] [1 2] [1 2] [1 2] [1 2])␤»
```

returns five distinct arrays (but with the same content each time), and

```raku
rand xx 3
```

returns three pseudo random numbers that are determined independently.

The right-hand side can be `*`, in which case a lazy, infinite list is returned. If it's a [`Bool`](/type/Bool), a [`Seq`](/type/Seq) with a single element is returned if it's `True`.

# [Concatenation](#Operators "go to top of document")[§](#Concatenation "direct link")

Same as the rest of the infix operators, these can be combined with metaoperators such as [assignment](#Assignment_operators), for instance.

## [infix `~`](#Operators "go to top of document")[§](#infix_~ "direct link")

```raku
multi infix:<~>(Any,   Any)
multi infix:<~>(Str:D, Str:D)
multi infix:<~>(Buf:D, Buf:D)
multi infix:<~>(Blob:D $a, Blob:D $b)
multi infix:<~>(Junction:D \a, Junction:D \b)
```

This is the string concatenation operator, which coerces both arguments to [`Str`](/type/Str) and concatenates them. If both arguments are [`Buf`](/type/Buf), a combined buffer is returned.

```raku
say 'ab' ~ 'c';     # OUTPUT: «abc␤»
my $bob = Blob.new([1,2,3]);
my $bao = Blob.new([3,4,5]);
say $bao ~ $bob;     # OUTPUT: «Blob:0x<03 04 05 01 02 03>␤»

```

The arity-1 version of this operator will be called when the hyper version of the operator is used on an array or list with a single element, or simply an element

```raku
say [~] Blob.new([3,4,5]);     # OUTPUT: «Blob:0x<03 04 05>␤»
say [~] 1|2;                   # OUTPUT: «any(1, 2)␤»

```

## [infix `o`, infix `∘`](#Operators "go to top of document")[§](#infix_o,_infix_∘ "direct link")

```raku
multi infix:<o>()
multi infix:<o>(&f)
multi infix:<o>(&f, &g --> Block:D)
```

The function composition operator `infix:<∘>` or `infix:<o>` combines two functions, so that the left function is called with the return value of the right function. If the [`.count`](/routine/count) of the left function is greater than 1, the return value of the right function will be [slipped](/type/Slip) into the left function.

Both `.count` and `.arity` of the right-hand side will be maintained, as well as the `.of` of the left hand side.

```raku
sub f($p){ say 'f'; $p / 2 }
sub g($p){ say 'g'; $p * 2 }

my &composed = &f ∘ &g;
say composed 2; # OUTPUT: «g␤f␤2␤»
# equivalent to:
say 2.&g.&f;
# or to:
say f g 2;
say &composed.arity; #  OUTPUT: «1␤»
say &composed.count; #  OUTPUT: «1␤»
say &composed.of;    #  OUTPUT: «(Mu)␤»

```

```raku
sub f($a, $b, $c) { [~] $c, $b, $a }
sub g($str){ $str.comb }
my &composed = &f ∘ &g;
say composed 'abc'; # OUTPUT: «cba␤»
# equivalent to:
say f |g 'abc';

```

The single-arg candidate returns the given argument as is. The zero-arg candidate returns an identity routine that simply returns its argument.

```raku
my &composed = [∘] &uc;
say composed 'foo'; # OUTPUT: «FOO␤»

my &composed = [∘];
say composed 'foo'; # OUTPUT: «foo␤»
```

# [Junctive AND (all) precedence](#Operators "go to top of document")[§](#Junctive_AND_(all)_precedence "direct link")

## [infix `&`](#Operators "go to top of document")[§](#infix_& "direct link")

```raku
multi infix:<&>($a, $b --> Junction:D) is assoc<list>
```

All junction operator.

Creates an *all* [`Junction`](/type/Junction) from its arguments. See [`Junction`](/type/Junction) for more details.

## [infix `(&)`, infix `∩`](#Operators "go to top of document")[§](#infix_(&),_infix_∩ "direct link")

```raku
multi infix:<(&)>(**@p)
```

Intersection operator.

'&' as in left hand side arguments 'and' right hand side arguments. Returns the **intersection** of all of its arguments. This creates a new [`Set`](/type/Set) that contains only the elements common to all of the arguments if none of the arguments are a [`Bag`](/type/Bag), [`BagHash`](/type/BagHash), [`Mix`](/type/Mix) or [`MixHash`](/type/MixHash).

```raku
say <a b c> (&) <b c d>; # OUTPUT: «Set(b c)␤»
say <a b c d> ∩ <b c d e> ∩ <c d e f>; # OUTPUT: «Set(c d)␤»

```

If any of the arguments are [`Baggy`](/type/Baggy) or [`Mixy`](/type/Mixy), the result is a new [`Bag`](/type/Bag) (or [`Mix`](/type/Mix)) containing the common elements, each weighted by the largest *common* weight (which is the minimum of the weights of that element over all arguments).

```raku
say <a a b c a> (&) bag(<a a b c c>); # OUTPUT: «Bag(a(2) b c)␤»

```

## [infix `(.)`, infix `⊍`](#Operators "go to top of document")[§](#infix_(.),_infix_⊍ "direct link")

```raku
multi infix:<(.)>(**@p)
```

Baggy multiplication operator.

Returns the Baggy **multiplication** of its arguments, i.e., a [`Bag`](/type/Bag) that contains each element of the arguments with the weights of the element across the arguments multiplied together to get the new weight. Returns a [`Mix`](/type/Mix) if any of the arguments is a [`Mixy`](/type/Mixy).

```raku
say <a b c> (.) <a b c d>; # OUTPUT: «Bag(a b c)␤»
                           # Since 1 * 0 == 0, in the case of 'd'
say <a a b c a d> ⊍ bag(<a a b c c>); # OUTPUT: «Bag(a(6) b c(2))␤»

```

# [Junctive OR (any) precedence](#Operators "go to top of document")[§](#Junctive_OR_(any)_precedence "direct link")

## [infix `|`](#Operators "go to top of document")[§](#infix_| "direct link")

```raku
multi infix:<|>($a, $b --> Junction:D) is assoc<list>
```

Creates an *any* [`Junction`](/type/Junction) from its arguments.

```raku
my $three-letters = /<[a b c]>/ | /<[i j k]>/ | /<[x y z]>/;
say $three-letters.raku; # OUTPUT: «any(/<[a b c]>/, /<[i j k]>/, /<[x y z]>/)␤»
say 'b' ~~ $three-letters; # OUTPUT: «True␤»
```

This first creates an `any` [`Junction`](/type/Junction) of three regular expressions (every one of them matching any of 3 letters), and then uses smartmatching to check whether the letter `b` matches any of them, resulting in a positive match. See also [`Junction`](/type/Junction) for more details.

## [infix `(|)`, infix `∪`](#Operators "go to top of document")[§](#infix_(|),_infix_∪ "direct link")

```raku
multi infix:<(|)>(**@p)
```

Union operator.

'|' as in left hand side arguments 'or' right hand side arguments.

Returns the **union** of all of its arguments. This creates a new [`Set`](/type/Set) that contains all the elements its arguments contain if none of the arguments are a [`Bag`](/type/Bag), [`BagHash`](/type/BagHash), [`Mix`](/type/Mix) or [`MixHash`](/type/MixHash).

```raku
say <a b d> ∪ bag(<a a b c>); # OUTPUT: «Bag(a(2) b c d)␤»

```

If any of the arguments are [`Baggy`](/type/Baggy) or [`Mixy`](/type/Mixy), the result is a new [`Bag`](/type/Bag) (or [`Mix`](/type/Mix)) containing all the elements, each weighted by the *highest* weight that appeared for that element.

```raku
say <a b d> ∪ bag(<a a b c>); # OUTPUT: «Bag(a(2) b c d)␤»

```

## [infix `(+)`, infix `⊎`](#Operators "go to top of document")[§](#infix_(+),_infix_⊎ "direct link")

```raku
multi infix:<(+)>(**@p)
```

Baggy addition operator.

Returns the Baggy **addition** of its arguments. This creates a new [`Bag`](/type/Bag) from each element of the arguments with the weights of the element added together to get the new weight, if none of the arguments are a [`Mix`](/type/Mix) or [`MixHash`](/type/MixHash).

```raku
say <a a b c a d> (+) <a a b c c>; # OUTPUT: «Bag(a(5) b(2) c(3) d)␤»

```

If any of the arguments is a [`Mixy`](/type/Mixy), the result is a new [`Mix`](/type/Mix).

```raku
say <a b c> (+) (a => 2.5, b => 3.14).Mix; # OUTPUT: «Mix(a(3.5) b(4.14) c)␤»

```

## [infix `(-)`, infix `∖`](#Operators "go to top of document")[§](#infix_(-),_infix_∖ "direct link")

```raku
multi infix:<(-)>(**@p)
```

Set difference operator.

Returns the **set difference** of all its arguments. This creates a new [`Set`](/type/Set) that contains all the elements the first argument has but the rest of the arguments don't, i.e., of all the elements of the first argument, minus the elements from the other arguments. But only if none of the arguments are a [`Bag`](/type/Bag), [`BagHash`](/type/BagHash), [`Mix`](/type/Mix) or [`MixHash`](/type/MixHash).

```raku
say <a a b c a d> (-) <a a b c c>; # OUTPUT: «Set(d)␤»
say <a b c d e> (-) <a b c> (-) <a b d>; # OUTPUT: «Set(e)␤»

```

If any of the arguments are [`Baggy`](/type/Baggy) or [`Mixy`](/type/Mixy), the result is a new [`Bag`](/type/Bag) (or [`Mix`](/type/Mix)) containing all the elements remaining after the first argument with its weight subtracted by the weight of that element in each of the other arguments.

```raku
say <a a b c a d> (-) bag(<a b c c>); # OUTPUT: «Bag(a(2) d)␤»
say <a a b c a d>  ∖  mix(<a b c c>); # OUTPUT: «Mix(a(2) c(-1) d)␤»

```

## [infix `^`](#Operators "go to top of document")[§](#infix_^ "direct link")

```raku
multi infix:<^>($a, $b --> Junction:D) is assoc<list>
```

One junction operator.

Creates a *one* [`Junction`](/type/Junction) from its arguments. See [`Junction`](/type/Junction) for more details.

## [infix `(^)`, infix `⊖`](#Operators "go to top of document")[§](#infix_(^),_infix_⊖ "direct link")

```raku
multi infix:<(^)>($a, $b)
multi infix:<(^)>(**@p)
```

Symmetric set difference operator.

Returns the **symmetric set difference** of all its arguments. This creates a new [`Set`](/type/Set) made up of all the elements that `$a` has but `$b` doesn't and all the elements `$b` has but `$a` doesn't if none of the arguments are a [`Bag`](/type/Bag), [`BagHash`](/type/BagHash), [`Mix`](/type/Mix) or [`MixHash`](/type/MixHash). Equivalent to `($a ∖ $b) ∪ ($b ∖ $a)`.

```raku
say <a b> (^) <b c>; # OUTPUT: «Set(a c)␤»

```

If any of the arguments are [`Baggy`](/type/Baggy) or [`Mixy`](/type/Mixy), the result is a new [`Bag`](/type/Bag) (or [`Mix`](/type/Mix)).

```raku
say <a b> ⊖ bag(<b c>); # OUTPUT: «Bag(a c)␤»

```

# [Named unary precedence](#Operators "go to top of document")[§](#Named_unary_precedence "direct link")

## [prefix `temp`](#Operators "go to top of document")[§](#prefix_temp "direct link")

```raku
sub prefix:<temp>(Mu $a is rw)
```

"temporizes" the variable passed as the argument. The variable begins with the same value as it had in the outer scope, but can be assigned new values in this scope. Upon exiting the scope, the variable will be restored to its original value.

```raku
my $a = "three";
say $a; # OUTPUT: «three␤»
{
    temp $a;
    say $a; # OUTPUT: «three␤»
    $a = "four";
    say $a; # OUTPUT: «four␤»
}
say $a; # OUTPUT: «three␤»
```

You can also assign immediately as part of the call to temp:

```raku
temp $a = "five";

```

Be warned the `temp` effects get removed once the block is left. If you were to access the value from, say, within a [`Promise`](/type/Promise) after the `temp` was undone, you'd get the original value, not the `temp` one:

```raku
my $v = "original";
{
    temp $v = "new one";
    start {
        say "[PROMISE] Value before block is left: `$v`";
        sleep 1;
        say "[PROMISE] Block was left while we slept; value is now `$v`";
    }
    sleep ½;
    say "About to leave the block; value is `$v`";
}
say "Left the block; value is now `$v`";
sleep 2;

# OUTPUT:
# [PROMISE] Value before block is left: `new one`
# About to leave the block; value is `new one`
# Left the block; value is now `original`
# [PROMISE] Block was left while we slept; value is now `original`

```

## [prefix `let`](#Operators "go to top of document")[§](#prefix_let "direct link")

```raku
sub prefix:<let>(Mu $a is rw)
```

Refers to a variable in an outer scope whose value will be restored if the block exits unsuccessfully, implying that the block returned a defined object.

```raku
my $name = "Jane Doe";

{
    let $name = prompt("Say your name ");
    die if !$name;
    CATCH {
        default { say "No name entered" }
    }
    say "We have $name";
}

say "We got $name";

```

This code provides a default name for `$name`. If the user exits from the prompt or simply does not provide a valid input for `$name`; `let` will restore the default value provided at the top. If user input is valid, it will keep that.

# [Nonchaining binary precedence](#Operators "go to top of document")[§](#Nonchaining_binary_precedence "direct link")

## [infix `does`](#Operators "go to top of document")[§](#infix_does "direct link")

```raku
sub infix:<does>(Mu $obj, Mu $role) is assoc<non>
```

Mixes `$role` into `$obj` at runtime. Requires `$obj` to be mutable.

Similar to [but](/routine/but) operator, if `$role` supplies exactly one attribute, an initializer can be passed in parentheses.

Similar to [but](/routine/but) operator, the `$role` can instead be an instantiated object, in which case, the operator will create a role for you automatically. The role will contain a single method named the same as `$obj.^name` and that returns `$obj`:

```raku
my $o = class { method Str { "original" } }.new;
put $o;            # OUTPUT: «original␤»
$o does "modded";
put $o;            # OUTPUT: «modded␤»
```

If methods of the same name are present already, the last mixed in role takes precedence.

## [infix `but`](#Operators "go to top of document")[§](#infix_but "direct link")

```raku
multi infix:<but>(Mu $obj1, Mu   $role) is assoc<non>
multi infix:<but>(Mu $obj1, Mu:D $obj2) is assoc<non>
```

Creates a copy of `$obj` with `$role` mixed in. Since `$obj` is not modified, `but` can be used to create immutable values with mixins.

If `$role` supplies exactly one attribute, an initializer can be passed in parentheses:

```raku
role Answerable {
    has $.answer;
}
my $ultimate-question = 'Life, the Universe and Everything' but Answerable(42);
say $ultimate-question;         # OUTPUT: «Life, the Universe and Everything␤»
say $ultimate-question.^name;   # OUTPUT: «Str+{Answerable}␤»
say $ultimate-question.answer;  # OUTPUT: «42␤»

```

Instead of a role, you can provide an instantiated object. In this case, the operator will create a role for you automatically. The role will contain a single method named the same as `$obj.^name` and that returns `$obj`:

```raku
my $forty-two = 42 but 'forty two';
say $forty-two+33;    # OUTPUT: «75␤»
say $forty-two.^name; # OUTPUT: «Int+{<anon|1>}␤»
say $forty-two.Str;   # OUTPUT: «forty two␤»

```

Calling `^name` shows that the variable is an [`Int`](/type/Int) with an anonymous object mixed in. However, that object is of type [`Str`](/type/Str), so the variable, through the mixin, is endowed with a method with that name, which is what we use in the last sentence.

We can also mixin classes, even created on the fly.

```raku
my $s = 12 but class Warbles { method hi { 'hello' } }.new;
say $s.Warbles.hi;    # OUTPUT: «hello␤»
say $s + 42;          # OUTPUT: «54␤»

```

To access the mixed-in class, as above, we use the class name as is shown in the second sentence. If methods of the same name are present already, the last mixed in role takes precedence. A list of methods can be provided in parentheses separated by comma. In this case conflicts will be reported at runtime.

## [infix `cmp`](#Operators "go to top of document")[§](#infix_cmp "direct link")

```raku
multi infix:<cmp>(Any,       Any)
multi infix:<cmp>(Real:D,    Real:D)
multi infix:<cmp>(Str:D,     Str:D)
multi infix:<cmp>(Version:D, Version:D)
```

Generic, "smart" three-way comparator.

Compares strings with string semantics, numbers with number semantics, [`Pair`](/type/Pair) objects first by key and then by value etc.

if `$a eqv $b`, then `$a cmp $b` always returns `Order::Same`.

```raku
say (a => 3) cmp (a => 4);   # OUTPUT: «Less␤»
say 4        cmp 4.0;        # OUTPUT: «Same␤»
say 'b'      cmp 'a';        # OUTPUT: «More␤»
```

Strings are compared codepoint by codepoint; if leading codepoints are the same, the result of comparing the first differing codepoint is returned or the longer string if their lengths differ.

```raku
"abcd" cmp "abcde";    # OUTPUT: «Less␤»
"abcd " cmp "abcde";   # OUTPUT: «Less␤»
'A' cmp 'Ẳ';           # OUTPUT: «Less␤»
```

## [infix `coll`](#Operators "go to top of document")[§](#infix_coll "direct link")

```raku
multi infix:<coll>(Str:D \a, Str:D \b --> Order:D)
multi infix:<coll>(Cool:D \a, Cool:D \b --> Order:D)
multi infix:<coll>(Pair:D \a, Pair:D \b --> Order:D)
```

`coll` is a sorting operator that takes pairs of [`Str`](/type/Str)s, [`Cool`](/type/Cool)s or [`Pair`](/type/Pair)s and returns an [`Order`](/type/Order) that uses the `$*COLLATION` order. The default behavior disregards diacritic marks and capitalization, for instance.

```raku
say "b" cmp "à";  # OUTPUT: «Less␤»
say "b" coll "à"; # OUTPUT: «More␤»
```

In the first case, lexicographic or codepoint order is taken into account. In the second, which uses `coll`, the diacritic is not considered and sorting happens according to intuitive order.

**NOTE:** These are not yet implemented in the JVM.

## [infix `unicmp`](#Operators "go to top of document")[§](#infix_unicmp "direct link")

```raku
multi infix:<unicmp>(Str:D \a, Str:D \b --> Order:D)
multi infix:<unicmp>(Pair:D \a, Pair:D \b --> Order:D)
multi infix:<coll>(Pair:D \a, Pair:D \b --> Order:D)
```

Unlike the cmp operator which sorts according to codepoint, `unicmp` and `coll` sort according to how most users would expect, that is, disregarding aspects of the particular character like capitalization.

```raku
say 'a' unicmp 'Z'; # OUTPUT: «Less␤»
say 'a' coll 'Z';   # OUTPUT: «Less␤»
say 'a' cmp 'Z';    # OUTPUT: «More␤»
```

The main difference between `coll` and `unicmp` is that the behavior of the former can be changed by the [`$*COLLATION`](/language/variables#index-entry-%24*COLLATION) dynamic variable.

**NOTE:** These are not yet implemented in the JVM.

## [infix `leg`](#Operators "go to top of document")[§](#infix_leg "direct link")

```raku
multi infix:<leg>(Any,   Any)
multi infix:<leg>(Str:D, Str:D)
```

String three-way comparator. Short for *less, equal or greater?*.

Coerces both arguments to [`Str`](/type/Str) and then does a lexicographic comparison.

```raku
say 'a' leg 'b';       # OUTPUT: «Less␤»
say 'a' leg 'a';       # OUTPUT: «Same␤»
say 'b' leg 'a';       # OUTPUT: «More␤»
```

## [infix `<=>`](#Operators "go to top of document")[§](#infix_<=> "direct link")

```raku
multi infix:«<=>»($a, $b --> Order:D) is assoc<non>
```

Numeric three-way comparator.

Coerces both arguments to [`Real`](/type/Real) and then does a numeric comparison.

## [infix `..`](#Operators "go to top of document")[§](#infix_.. "direct link")

```raku
multi infix:<..>($a, $b --> Range:D) is assoc<non>
```

Range operator

Constructs a [`Range`](/type/Range) from the arguments.

## [infix `..^`](#Operators "go to top of document")[§](#infix_..^ "direct link")

```raku
multi infix:<..^>($a, $b --> Range:D) is assoc<non>
```

Right-open range operator.

Constructs a [`Range`](/type/Range) from the arguments, excluding the end point.

## [infix `^..`](#Operators "go to top of document")[§](#infix_^.. "direct link")

```raku
multi infix:<^..>($a, $b --> Range:D) is assoc<non>
```

Left-open range operator.

Constructs a [`Range`](/type/Range) from the arguments, excluding the start point.

## [infix `^..^`](#Operators "go to top of document")[§](#infix_^..^ "direct link")

```raku
multi infix:<^..^>($a, $b --> Range:D) is assoc<non>
```

Open range operator.

Constructs a [`Range`](/type/Range) from the arguments, excluding both start and end point.

# [Chaining binary precedence](#Operators "go to top of document")[§](#Chaining_binary_precedence "direct link")

## [infix `==`, infix `⩵`](#Operators "go to top of document")[§](#infix_==,_infix_⩵ "direct link")

```raku
multi infix:<==>(Any, Any)
multi infix:<==>(Int:D, Int:D)
multi infix:<==>(Num:D, Num:D)
multi infix:<==>(Rational:D, Rational:D)
multi infix:<==>(Real:D, Real:D)
multi infix:<==>(Complex:D, Complex:D)
multi infix:<==>(Numeric:D, Numeric:D)
```

Numeric equality operator.

Coerces both arguments to [`Numeric`](/type/Numeric) (if necessary); returns `True` if they are equal.

Since Rakudo version 2021.07, ⩵ is an alias for this operator.

## [infix `!=`, infix `≠`](#Operators "go to top of document")[§](#infix_!=,_infix_≠ "direct link")

```raku
sub infix:<!=>(Mu, Mu --> Bool:D)
```

Numeric inequality operator.

Coerces both arguments to [`Numeric`](/type/Numeric) (if necessary); returns `True` if they are distinct.

Is equivalent to `!==`.

## [infix `<`](#Operators "go to top of document")[§](#infix_< "direct link")

```raku
multi infix:«<»(Int:D, Int:D)
multi infix:«<»(Num:D, Num:D)
multi infix:«<»(Real:D, Real:D)
```

Numeric less than operator.

Coerces both arguments to [`Real`](/type/Real) (if necessary); returns `True` if the first argument is smaller than the second.

## [infix `<=`, infix `≤`](#Operators "go to top of document")[§](#infix_<=,_infix_≤ "direct link")

```raku
multi infix:«<=»(Int:D, Int:D)
multi infix:«<=»(Num:D, Num:D)
multi infix:«<=»(Real:D, Real:D)
```

Numeric less than or equal to operator.

Coerces both arguments to [`Real`](/type/Real) (if necessary); returns `True` if the first argument is smaller than or equal to the second.

## [infix `>`](#Operators "go to top of document")[§](#infix_> "direct link")

```raku
multi infix:«>»(Int:D, Int:D)
multi infix:«>»(Num:D, Num:D)
multi infix:«>»(Real:D, Real:D)
```

Numeric greater than operator.

Coerces both arguments to [`Real`](/type/Real) (if necessary); returns `True` if the first argument is larger than the second.

## [infix `>=`, infix `≥`](#Operators "go to top of document")[§](#infix_>=,_infix_≥ "direct link")

```raku
multi infix:«>=»(Int:D, Int:D)
multi infix:«>=»(Num:D, Num:D)
multi infix:«>=»(Real:D, Real:D)
```

Numeric greater than or equal to operator.

Coerces both arguments to [`Real`](/type/Real) (if necessary); returns `True` if the first argument is larger than or equal to the second.

## [infix `eq`](#Operators "go to top of document")[§](#infix_eq "direct link")

```raku
multi infix:<eq>(Any,   Any)
multi infix:<eq>(Str:D, Str:D)
```

String equality operator.

Coerces both arguments to [`Str`](/type/Str) (if necessary); returns `True` if both are equal.

Mnemonic: *equal*

## [infix `ne`](#Operators "go to top of document")[§](#infix_ne "direct link")

```raku
multi