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)
Category: Chapter 2. Operators
π Assign operator = in Perl 6
= assigns a value to a variable.
π 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”