min and max return, correspondently, the minimum and maximum value of their operands. say 20 min 10; # 10 say ‘three’ max ‘two’; # two (sorted alphabetically)
= assigns a value to a variable.
, 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”
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”
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”
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”
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 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”