πŸ”¬70. Examining the enum type in Perl 6

In Perl 6, you can create enumerations like this: enum colour <red orange yellow green blue violet>; Having this said, you can use the new name as a type name and create variables of that type: my colour $c; $c = green; say $c; # green say $c.Int; # 3 As you would rightly expect, … Continue reading “πŸ”¬70. Examining the enum type in Perl 6”

πŸ¦‹ 69. Setting timeouts in Perl 6

In Perl 5, I used to set timeouts using signals (or, at least, that was an easy and predictable way). In Perl 6, you can use promises. Let us see how to do that. To imitate a long-running task, create an infinite loop that prints its state now and then. Here it is: for 1 … Continue reading “πŸ¦‹ 69. Setting timeouts in Perl 6”

πŸ”¬68. The smartness of the sequence operator in Perl 6, part 1

In Perl 6, you can ask the sequence operator to build a desired sequence for you. It can be arithmetic or geometric progression. All you need is to show the beginning of the sequence to Perl, for example: .say for 3, 5 … 11; This prints numbers 3, 5, 7, 9, and 11. Or: .say … Continue reading “πŸ”¬68. The smartness of the sequence operator in Perl 6, part 1”

πŸ”¬67. Redeclaration of a symbol in Perl 6

Today, we will see how Perl 6 helps to keep our programs better. Redeclaration of a variable Examine the following program: my $x = 1; my $x = 2; say $x; You can immediately see that this program is not entirely correct. Either we meant to assign a new value to $x or to create … Continue reading “πŸ”¬67. Redeclaration of a symbol in Perl 6”

πŸ¦‹ 66. Atomic operations in Perl 6

N. B. The examples below require a fresh Rakudo compiler, at least of the version 2017.09. Discussing parallel computing earlier or later leads to solving race conditions. Let us look at a simple counter that is incremented by two parallel threads: my $c = 0; await do for 1..10 { start { $c++ for 1 … Continue reading “πŸ¦‹ 66. Atomic operations in Perl 6”