πŸ“˜ Method postfix operator .^ in Perl 6

.^method calls a method on the object’s metaobject. A metaobject is an instance of the HOW class and contains some additional information about the object. The following two operations, applied to the $i variable, are equivalent and print the list of the methods available for the Int variables. my Int $i; say $i.^methods(); say $i.HOW.methods($i);

πŸ“˜ Infix operators in Perl 6

Infix operators are placed in a programme between two operands. The majority of the infix operators are binary, and there is a single ternary operator, which expects three operands. The simplest example of the binary operator is an addition operator +. On the right and left sides it expects two values, for example, two variables: … Continue reading “πŸ“˜ Infix operators in Perl 6”

πŸ“˜ Universal comparison operator === in Perl 6

=== returns a True value if both operands are the same value. Otherwise, it returns False. This operator is also known as the value identity operator. class I { }Β  # Three different instances my $i = I.new; my $ii = I.new; my $iii = I.new;Β  my @a = ($i, $ii, $iii); for @a -> … Continue reading “πŸ“˜ Universal comparison operator === in Perl 6”

πŸ“˜ Method postfix operator .= in Perl 6

.=method is a mutating call of the method on an object. The call $x.=method does the same as the more verbose assignment $x = $x.method. In the following example, the $o container initially holds an object of the C class, but after $o.=m(), the value will be replaced with an instance of the D class. … Continue reading “πŸ“˜ Method postfix operator .= in Perl 6”

πŸ“˜ Numeric operators +, -, *, and / in Perl 6

+, -, *, and / are the operators executing the corresponding arithmetical operations and do not require any comments. When working with Perl 6, keep in mind that before the operation is executed, the operands will be automatically converted to the Numeric type if it is necessary.

πŸ“˜ Numeric operators div and mod in Perl 6

div is the integer division operator. If the floating point is truncated, the result is rounded to the preceding lower integer. say 10 div 3;Β  # 3 say -10 div 3; # -4 mod is another form of the modulo: say 10 % 3;Β Β  # 1 say 10 mod 3; # 1 Unlike the / … Continue reading “πŸ“˜ Numeric operators div and mod in Perl 6”

πŸ“˜ Chapter 2. Operators in Perl 6

The meanings of the many of the operators in Perl 6 are quite obvious even for those who are not familiar with Perl 5. On the other hand, sometimes the behaviour of the operator contains some tiny details that you may not think of. In this chapter, we will list some operators, giving some comments … Continue reading “πŸ“˜ Chapter 2. Operators in Perl 6”

πŸ“˜ Zip operator Z in Perl 6

Z is the zip operator. It mixes the content of its two operands like a zipper does. The operator continues mixing while there are enough data in both operands. The code @c = @a Z @b; is equivalent to the following: @c = ((@a[0], @b[0]), (@a[1], @b[1]), …); Consider another example: my @a = ^5; … Continue reading “πŸ“˜ Zip operator Z in Perl 6”

πŸ“˜ Zip meta-operator Z in Perl 6

The zip meta-operator prefix, Z, combines the corresponding elements of its list operands like the zipper does. The record @a Z+ @b is equivalent to this (in Perl 6, the last element of an array is indexed as *-1, not just -1; see the details in Appendix): ((@a[0] + @b[0]), (@a[1] + @b[1]), . . … Continue reading “πŸ“˜ Zip meta-operator Z in Perl 6”