Print ‘Hello, World!’ There are two built-in functions in Perl 6 to print to the console: printand say. Both print their arguments, but the say routine additionally ends the output with a newline character. So, the quickest solution is to use sayand pass a string with no newlines: say ‘Hello, World!’ Another solution is to use print and include the \n character … Continue reading “📘 Hello, World! in Perl 6”
Author: Andrew Shitov
📘 How to debug Perl 6 programs
For quick tests, use the compiler in the mode of the REPL (read—eval—print loop) shell. Just run the perl6 command: $ perl6To exit type ‘exit’ or ‘^D’> With bigger programs, one of the following techniques helps to visualise data: 1. The say routine is used as a stand-alone function or as an object method. It works well … Continue reading “📘 How to debug Perl 6 programs”
🦋 109. 42 via the cubes
In the recent days, you might have seen the calculation that leads to getting an exact value of 42, the answer of Life, the Universe and Everything. Let me copy it here, using the power of Perl 6 and its arbitrary precision arithmetics , not to mention the coolness of using superscripts directly in the … Continue reading “🦋 109. 42 via the cubes”
The PerlCon 2019 conference in Rīga behind the scene
I have just arrived home after about two weeks spent in Rīga, where we were hosting this year’s European Perl 5 and Perl 6 conference. The organisation processes started a year ago, and by we I mean myself and my business partner, who joined about 7-8 months ago. PerlCon is an annual European conference dedicated to the Perl … Continue reading “The PerlCon 2019 conference in Rīga behind the scene”
🦋 108. Basic usage of NativeCall in Perl 6
NativeCall is both a module and a technology in Perl 6 that allows you to call C functions from your Perl 6 code. Today, let’s meet the most basic usage. Take the rand() function from the C standard library: #include <stdio.h> #include <stdlib.h> int main() { int r = rand(); printf(“%i\n”, r); return 0; } … Continue reading “🦋 108. Basic usage of NativeCall in Perl 6”
💡 107. Odd-even sort in Perl 6
In the Odd-Even sort, or Brick sort, you take every second element and swap it with the next one if they are not sorted. Then you take the same elements and swap it with the previous element if they are not ordered. You continue until you are done. You can formulate the algorithm a bit … Continue reading “💡 107. Odd-even sort in Perl 6”
💡 106. Gnome sort in Perl 6
Our today’s topic is the Gnome sort, which is also referred to as Stupid sort. To sort an array using this method, you scan the data from left to right and check the two adjacent items to see if they are ordered properly. If they are, you go forward. If not, you swap the elements … Continue reading “💡 106. Gnome sort in Perl 6”
💡 105. Pancake sort in Perl 6
The Pancake sort is an interesting method of sorting data, as unlike more traditional sorting algorithms, it operates with piles of data on each step. You have to imagine data as a pile of pancakes, the values corresponding to the size of pancakes. The only allowed operation is flipping a pile of ‘pancakes.’ It can … Continue reading “💡 105. Pancake sort in Perl 6”
💡 104. Stooge sort in Perl 6
Have you ever heard of the Stooge sort algorithm? If not, it is quite interesting to learn it. The idea is clear, while you maybe need some time to see if it really works. So, take a list of numbers and swap the first and the last elements if they are not sorted properly (that … Continue reading “💡 104. Stooge sort in Perl 6”
💡 103. Merge sort in Perl 6
Welcome to another sorting episode, this time we’ll talk about Merge sort in Perl 6. In Merge sort, you first split the data into halves until the pieces become atomic (in the original meaning of the word), that is either each piece contains a single element, or, after the current split, the second part contains … Continue reading “💡 103. Merge sort in Perl 6”
💡 102. Insertion sort in Perl 6
Today, we are investigating the Insertion sort algorithm and its possible implementation in Perl 6. The algorithm’s complexity is O(n2), but it is a good candidate to practice some Perl 6. The idea is simple. You find the minimum value in the array and put it to the first position. Then you scan the data … Continue reading “💡 102. Insertion sort in Perl 6”
💡 101. Quick sort in Perl 6
Today, let’s look at another, and presumably the most well known method of sorting data, Quick sort. The algorithm requires you to select the so-called pivot, one of the element from the data, and split the rest in two parts: the elements less than the pivot, and the elements more or equals to the pivot. … Continue reading “💡 101. Quick sort in Perl 6”
💡 100. Bubble sort in Perl 6
Hey everyone, let’s implement some algorithms in Perl 6. The first one will be the classical Bubble sort. In essence, you scan the data from left to right and swap the two adjacent items if they are not ordered properly yet. Repeat until the whole data list is ordered. Here’s the initial straightforward implementation: sub … Continue reading “💡 100. Bubble sort in Perl 6”
📺 Perl 6 One-Liners slides
Here are the slides of my talk at the German Perl Workshop 2019 in Munich, which summarises a Christmas series of posts written last year. Lots of Perl 6 one-liners and related stuff such as the usage of the MAIN function. Video recording should also appear soon. Update. The video is ready.
📺 Creating a compiler in Perl 6
At the German Perl Workshop 2019 in Munich, I gave a presentation about how to create compilers and interpreters using Perl 6 grammars. This talk differs from my previous talks on this subject, so if you’ve seen them, I hope you will also enjoy this one. There was a video recording during the talk, I … Continue reading “📺 Creating a compiler in Perl 6”
📺 Perl 6 as a new tool for language compilers
Here’s my recent talk from FOSDEM in Brussels, given on 3 February 2019. Perl 6 grammars are a great way to describe the grammar and implement an interpreter or a compiler of DSL or a programming language. In this talk, I will demonstrate how you can do it. During the talk, we will create an … Continue reading “📺 Perl 6 as a new tool for language compilers”
🎄 26/25. Overview of the Perl 6 One-Liner Advent Calendar 2018
The Perl 6 One-Liner Advent Calendar 2018 is over! Let’s make a quick overview of what we have covered so far. There were a few themes covered. First, some one-liners from the Perl 6 Calendar 2019 were explained in more detail. We looked at how to generate random passwords and random integers, how to print … Continue reading “🎄 26/25. Overview of the Perl 6 One-Liner Advent Calendar 2018”
🎄 25/25. Tips and ideas for the Perl 6 Golf code
Welcome to Day 25, the last day of the Perl 6 One-Liner Advent Calendar! Traditional advent calendars have only 24 entries, and our bonus post today will be dedicated to some tips and tricks that you can use in Perl 6 golf contest. There is a great site, code-golf.io, where you can try solving a … Continue reading “🎄 25/25. Tips and ideas for the Perl 6 Golf code”
🎄 24/25. Reading files with $*ARGFILES in Perl 6
Welcome to Day 24 of the Perl 6 One-Liner Advent Calendar! In the previous days, we were reading text files, so it would be logical to talk about $*ARGFILES, a built-in dynamic variable that may be handy when working with multiple input files. How do you read two or more files passed in the command-line? … Continue reading “🎄 24/25. Reading files with $*ARGFILES in Perl 6”
🎄 23/25. Calculating totals with Perl 6
Welcome to Day 23 of the Perl 6 One-Liner Advent Calendar! End of the year is the time when people evaluate there year results, and Perl 6 can help with that, too. Today, we’ll see a one-liner that calculates totals for the columns of a table. Here’s some sample data in a file: 100.20 303.50 … Continue reading “🎄 23/25. Calculating totals with Perl 6”