Concurrent atomic operations in C++ and Raku

Here’s a problem to solve: you have two threads, each incrementing the same single counter N times. What is the state of the counter at the end of the program? A straightforward solution A naïve C++ program can be written using the standard library threads like this: #include <iostream> #include <thread> int counter; void f() {     for (int c = 0; c != 100000; c++) counter++; } int main() {     std::thread thread_a {f}; … Continue reading “Concurrent atomic operations in C++ and Raku”

Raku One-Liners — a free book

Let me announce the new book, Raku One-Liners. The book is available in the PDF format for free. Later, paper copies will also be available. Download the Raku One-Liners book now N.B. As of today, the book is in the test mode, and a few updated PDF versions will be uploaded in a few days. … Continue reading “Raku One-Liners — a free book”

🦋 110. is rw vs is raw in Raku

The cryptic title should not stop you from seeing bits of the regular Raku code. Namely, the two traits that you can add to function arguments: is rw and is raw. These two traits may look confusing because both allow changing the passed variable: sub f1($x is rw) {     say $x; } sub f2($x is raw) {     say $x; } my $a = 42; f1($a); # 42 f2($a); … Continue reading “🦋 110. is rw vs is raw in Raku”

Using Raku — a free book

Let me announce the second edition of my Using Perl 6 book. This time, it is published under the new name, Using Raku. The book is available in the PDF format for free. Later, paper copies will also be available. Download the Using Raku book now This is not a bare text replacement s/perl6/raku/. This … Continue reading “Using Raku — a free book”

📘 The Brainfuck interpreter written in Perl 6

Create the interpreter for the Brainfuck language. Brainfuck is an esoteric programming language that has a small set of instructions, each of them a single punctuation character. It is assumed that the Brainfuck program has built-in data memory, which is an array of integers, and a pointer to the currently selected item. The two instructions, + … Continue reading “📘 The Brainfuck interpreter written in Perl 6”

📘 Converting Morse to text using Perl 6

Convert the Morse sequence to plain text. To save efforts in typing the decoding table, we can use the %code hash from Task 98, Text to Morse code, and create the ‘inversed’ hash, where the keys are the Morse sequences, and the values are letters or digits: my %char = %code.kv.reverse; Printing this variable shows its contents … Continue reading “📘 Converting Morse to text using Perl 6”

📘 Converting text to Morse code using Perl 6

Convert the given text to the Morse code. Converting text to the Morse code is a relatively easy task. The solution is to replace all the alphanumeric characters with the corresponding representation in the Morse code. In this solution, all the other characters are ignored and are removed from the source string. In the Morse … Continue reading “📘 Converting text to Morse code using Perl 6”

📘 Reading directory content using Perl 6

Print the file names from the current directory. Reading a directory in Perl 6 can be done using the dir routine defined in the IO::Path class. say dir(); This tiny program does not do the task really satisfactory, as the dir routine returns a lazy sequence (an object of the Seq data type) of IO::Path objects. To get the textual … Continue reading “📘 Reading directory content using Perl 6”