πŸ“˜ 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”

πŸ“˜ Typed variables in Perl 6

This is how you declare a typed variable: my Int $x; Here, a scalar container $x may only hold an integer value. Attempts to assign it a value that is not an integer leads to an error: my Int $x; $x = “abc”; # Error: Type check failed in assignment to ‘$x’; Β Β Β Β Β Β Β Β Β Β Β  # expected … Continue reading “πŸ“˜ Typed variables in Perl 6”

πŸ“˜ String concatenation operator ~ in Perl 6

~ does the string concatenation. The dot in Perl 6 is now used for dealing with methods; thus, a new operator for the string concatenation was required. The tilde was a good candidate because it is also used in other string-related operators in Perl 6. say “a” ~ “b”; # ab If necessary, the operator … Continue reading “πŸ“˜ String concatenation operator ~ in Perl 6”