πŸ“˜ List creation operator , in Perl 6

, creates a List object. Note that this operator, as a few mentioned above, can be chained to accept more than two operands. my $what = (1, 2, 3); say $what.WHAT; # (List) The comma is also used as a separator of parameters passed to the subroutine. To create an empty list, use a pair … Continue reading “πŸ“˜ List creation operator , in Perl 6”

πŸ“˜ Assignment meta-operator = in Perl 6

The design of the operators in Perl 6 is very consistent. For example, if you add a new operator to the language, Perl 6 will create a few more to keep the harmony. In this section, we will talk about the so-called meta-operators, the operators over other operators. The assignment meta-operators (=) use the other … Continue reading “πŸ“˜ Assignment meta-operator = in Perl 6”

πŸ“˜ Reduction meta-operator [ ] in Perl 6

For any infix operator op the reduction form [op] also exists. The reduction operator takes a list, enrols its values, and inserts the operator between them. Examine the example with the [*] reduction operator: [*] 1..5 The form above is equivalent to the following line: 1 * 2 * 3 * 4 * 5 Reduction … Continue reading “πŸ“˜ Reduction meta-operator [ ] in Perl 6”

πŸ“˜ Reverse meta-operator R in Perl 6

The prefix R forms the reverse operator for the infix operators, such as / or cmp. The reverse operator does the same as the original but changes the order of the operands. If necessary, it also changes the operator’s associativity. This matters when you have more than two operands in a row. For example, in … Continue reading “πŸ“˜ Reverse meta-operator R in Perl 6”

πŸ“˜ Cross meta-operator X in Perl 6

The cross meta-operator prefix, X, applies an operation to all the possible combinations of the elements of the operands that are treated in list context. The result of the cross-operation is also a list. Here is an example that prints the coordinates for all the cells of a chess board: say ‘a’..’h’ X~ 1..8;

πŸ“˜ Hyper-operators in Perl 6

Hyper-operators modify regular operators in such a way that the operation is applied to all the element of a list operand. Both unary and binary operators may be written in the hyper-operator form. To create a hyper-operator, add a pair of >> and/or << to the operation sign. Let’s start with a simple unary operator … Continue reading “πŸ“˜ Hyper-operators in Perl 6”