Today, the journey to the internals of Int continues and first let’s make a deep dive into one on of the fascinating methods, is-prime. If you never used it, this is a great method that implements the logic, which is usually not built-in in a programming language. It is also great because primality is an … Continue reading “🔬29. Exploring the Int type in Perl 6, part 2”
Category: Perl 6 Internals
🔬28. Exploring the Int type in Perl 6, part 1
Actually, we already started looking at the internals of the Int data type two days ago, but today we’ll start from the very beginning. So, the Int data type. It is a great data type for practical programming and it is also widely used in Rakudo itself. For example, the Rational object is an object … Continue reading “🔬28. Exploring the Int type in Perl 6, part 1”
🔬27. Obsolete syntax error messages in Perl 6, part 4
So far, we covered a lot of different error messages that Rakudo Perl 6 generates when you accidentally use the Perl 5 syntax. This is a really nice feature for easy migration to the new language. Let us continue and cover another couple of errors. new X It was one of the hottest topics in … Continue reading “🔬27. Obsolete syntax error messages in Perl 6, part 4”
🔬26. Native integers and UInt in Perl 6
As soon as we touched some native integers yesterday, let us look a bit closer at them. The topic is deep, so we limit ourselves with a brief understanding of interconnections between the different integer data types in Perl 6. UInt and UInt64 The simplest is UInt. This data type is defined in src/core/Int.pm and … Continue reading “🔬26. Native integers and UInt in Perl 6”
🔬25. The Range method
Today, I started looking into the internals of the Int class (src/core/Int.pm) and faced a strangely looking method, Range. The Range method returns an object of the Range type showing the minimum and the maximum values that the object can hold. For example, this is how the method is defined for the Num class: method … Continue reading “🔬25. The Range method”
🔬24. Obsolete syntax error messages in Perl 6, part 3
A couple of weeks ago, we looked at some error messages that Perl 6 generates when it sees the Perl 5 constructions. Let us continue and go through another portion of the messages that are there in today’s Rakudo. \x[] We start with a simple error message that informs you to use new syntax when … Continue reading “🔬24. Obsolete syntax error messages in Perl 6, part 3”
🔬23. The internals of the ternary operator in Perl 6
Yesterday, we saw that the ternary operator is treated as an infix in the Perl 6 Grammar. The code between the two parts of the operator is caught by the <EXPR> method: token infix:sym<?? !!> { :my $*GOAL := ‘!!’; $<sym>=’??’ <.ws> <EXPR(‘i=’)> [ ‘!!’ . . . ] <O(|%conditional, :reducecheck<ternary>, :pasttype<if>)> } Now, our attraction … Continue reading “🔬23. The internals of the ternary operator in Perl 6”
🔬22. The infix nature of the ternary operator in Perl 6
The ternary operator ?? !! takes three operands, obviously. Although, it is said in the documentation that the operator is an infix. Let us figure out why. Here is the fragment from the Grammar that handles the ternary operator: token infix:sym<?? !!> { :my $*GOAL := ‘!!’; $<sym>=’??’ <.ws> <EXPR(‘i=’)> [ ‘!!’ || <?before ‘::’ <.-[=]>> … Continue reading “🔬22. The infix nature of the ternary operator in Perl 6”
🔬21. The tolerance operator in Perl 6
In Perl 6, there is a so-called approximately-equal operator =~=. It compares two numbers approximately. If both values are non-zero, the operator calculates their relative difference; the tolerance is defined by the $*TOLERANCE variable, which equals to 1E-15 by default. So, for two numbers $a and $b, the result (in pseudo-code) is: |$a – $b| … Continue reading “🔬21. The tolerance operator in Perl 6”
🔬20. What does nqp::getattr do in Perl 6?
In the previous posts, we saw many examples of calling NQP functions from the Perl 6 modules. One of the frequent calls was nqp::getattr. Let us see what that function does. Here are a couple of recent examples: nqp::isge_i($pos,0) && nqp::isconcrete(nqp::getattr(self,List,’$!reified’)) . . . nqp::if( nqp::iseq_i( nqp::getattr( nqp::getattr($self,Code,’$!signature’), Signature, ‘$!count’ ),1) When you first look at … Continue reading “🔬20. What does nqp::getattr do in Perl 6?”
🔬19. Digging into @a[*-1] in Perl 6
After a big work that we had yesterday to understand what’s going on when you try to subscript an array with a negative index, let’s see what actually happens behind the new syntax of getting the last element of an array as @a[*-1]. So, here’s a test program: my @a = <a b c>; say … Continue reading “🔬19. Digging into @a[*-1] in Perl 6”
🔬18. Implementing negative array subscripts in Perl 6
A few days ago, we saw how Perl 6 checks the syntax if you are trying to index an array with negative indices. Since then, I was thinking about implementing the support of @a[-1]. It was not that easy, that’s why I did not demonstrate this last time 🙂 Before going further, a small disclaimer. … Continue reading “🔬18. Implementing negative array subscripts in Perl 6”
🔬16. Unifying the implementation of ‘say’ in Perl 6
For the last two days, the topic of this blog was the internals of the say routine in Rakudo Perl 6. (By the way, the term routine is a good choice if you need to talk about both subs and methods.) In src/core/io_operators.pm, other routines are also defined. The main focus of today is on the … Continue reading “🔬16. Unifying the implementation of ‘say’ in Perl 6”
🔬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”
🔬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”