🔬15. Variants of ‘say’ in Perl 6

Yesterday, we saw four different variants of the multi sub called say. Today, let’s look at them more precisely. The functions are located in the src/core/io_operators.pm file. Start with the first and the simplest one: multi sub say() { $*OUT.print-nl } It just prints the newline to the $*OUT stream. Probably, it would be wise … Continue reading “🔬15. Variants of ‘say’ in Perl 6”

🔬14. Tracking down the ‘say’ calls in Perl 6

Welcome back! Today, we’ll try to do a simple thing using some knowledge from the previous days. Compare the two lines: say ‘Hello, World’; ‘Hello, World’.say; Is there any difference between them? Well, of course. Although the result is the same in both cases, syntactically they differ a lot. In the first case, say is … Continue reading “🔬14. Tracking down the ‘say’ calls in Perl 6”

🔬13. Let 1 + 2 * 3 = 9

Is it easy to break the behaviour of Perl 6? Well, the answer probably depends on what exactly you want to break. Playing with operator precedence, I wanted to change the rules of arithmetical operators + and * so that they are executed in different order, namely, multiplication first, addition second. Sounds like an easy … Continue reading “🔬13. Let 1 + 2 * 3 = 9”

🔬12. The beginning of the Grammar of Perl 6

Yesterday, we talked about the stages of the compiling process of a Perl 6 program and saw the parse tree of a simple ‘Hello, World!’ program. Today, our journey begins at the starting point of the Grammar. So, here is the program: say ‘Hello, World!’ The grammar of Perl 6 is written in Not Quite Perl … Continue reading “🔬12. The beginning of the Grammar of Perl 6”

🦋11. Compiler stages and targets in Perl 6

Welcome to the new year! Today, let us switch for a while from the discussion about obsolete messages to something different. Stages If you followed the exercises in the previous posts, you might have noticed that some statistics was printed in the console when compiling Rakudo: Stage start : 0.000 Stage parse : 44.914 Stage syntaxcheck: … Continue reading “🦋11. Compiler stages and targets in Perl 6”

🔬10. Obsolete syntax error messages, part 2

Today, we continue exploring the error messages that Rakudo developers embedded to detect old Perl 5 constructions in the Perl 6 code. The obs method But first, let’s make a small experiment and add a call to the obs method in the rule parsing the for keyword. rule statement_control:sym<for> { <sym><.kok> {} [ <?before ‘my’? … Continue reading “🔬10. Obsolete syntax error messages, part 2”

🔬9. Obsolete syntax error messages in Perl 6, part 1

Yesterday, we saw an error message about the improper syntax of the ternary operator. Let’s look at other similar things that the Rakudo designers has implemented for us to make the transition from Perl 5 smoother. First of all, the Perl 6 grammar file (src/Perl6/Grammar.nqp) contains four different methods for reacting to obsolete syntax: method … Continue reading “🔬9. Obsolete syntax error messages in Perl 6, part 1”

🔬8. Digging into operator precedence in Perl 6, part 2

Yesterday, we took a look at how the ? and so operators are dispatched depending on the type of the variable. We did it with the intention to understand what is the difference between them. Here is once again an excerpt from the src/core/Bool.pm file, where the bodies of the subs look alike: proto sub … Continue reading “🔬8. Digging into operator precedence in Perl 6, part 2”

🔬7. Digging into operator precedence in Perl 6, part 1

Today, we’ll once again look at the src/core/Bool.pm file. This is a good example of a full-fledged Perl 6 class, which is still not very difficult to examine. Look at the definitions of the ? and so operators: proto sub prefix:<?>(Mu $) is pure {*} multi sub prefix:<?>(Bool:D \a) { a } multi sub prefix:<?>(Bool:U … Continue reading “🔬7. Digging into operator precedence in Perl 6, part 1”

🔬6. The dd routine of Rakudo Perl 6

In Rakudo, there is a useful routine dd, which is not a part of Perl 6 itself. It dumps its argument(s) in a way that you immediately see the type and content of a variable. For example: $ ./perl6 -e’my Bool $b = True; dd($b)’ Bool $b = Bool::True It works well with data of … Continue reading “🔬6. The dd routine of Rakudo Perl 6”

🔬5. Lurking behind interpolation in Perl 6

In the previous articles, we’ve seen that the undefined value cannot be easily interpolated in a string, as an exception occurs. Today, our goal is to see where exactly that happens in the source code of Rakudo. So, as soon as we’ve looked at the Boolean values, let’s continue with them. Open perl6 in the … Continue reading “🔬5. Lurking behind interpolation in Perl 6”

🔬4. Exploring the Bool type in Perl 6, part 2

Today, we are continuing reading the source codes of the Bool class: src/core/Bool.pm, and will look at the methods that calculate the next or the previous values, or increment and decrement the values. For the Boolean type, it sounds simple, but you still have to determine the behaviour of the edge cases. pred and succ … Continue reading “🔬4. Exploring the Bool type in Perl 6, part 2”

🔬3. Playing with the code of Rakudo Perl 6

Yesterday, we looked at the two methods of the Bool class that return strings. The string representation that the functions produce is hardcoded in the source code. Let’s use this observation and try changing the texts. So, here is the fragment that we will modify: Bool.^add_multi_method(‘gist’, my multi method gist(Bool:D:) { self ?? ‘True’ !! … Continue reading “🔬3. Playing with the code of Rakudo Perl 6”

🦋1. The proto keyword in Perl 6

Today, we are looking precisely at the proto keyword. It gives a hint for the compiler about your intention to create multi-subs. Example 1 Consider an example of the function that either flips a string or negates an integer. multi sub f(Int $x) {     return -$x; } multi sub f(Str $x) {   … Continue reading “🦋1. The proto keyword in Perl 6”

Interview with Reini Urban

Reini Urban is the author of alternative Perl compilers. In this interview he talks about his work, discusses their internals and shares his thoughts about different approaches to make Perl faster. Before it all started How and when did you learn to program? My father was electrical and mechanical engineer and had a small enterprise … Continue reading “Interview with Reini Urban”

Interview with Carl Mäsak

Carl Mäsak is an application developer for Perl 6. He is the number one Perl 6 bug reporter, the author of November, one of the first real web applications written in Perl 6. October You started following the Perl 6 development in 2003–2004, a few years after the Perl 6 project was announced. What was … Continue reading “Interview with Carl Mäsak”

Interview with Stevan Little

Stevan Little is the author of Moose, the library introducing Perl 6-inspired classes in Perl 5. He also started the p5-mop project, which was aimed to bring classes to the Perl 5’s core. Perl and OOP Once you said that it was Damian Conway’s “Object Oriented Perl” book, which gave you the idea of real … Continue reading “Interview with Stevan Little”