Yesterday, we talked about how modification of the value such as 0 but True works in Rakudo Perl 6. Today, we’ll try to fix a missing fragment in the implementation, which does not let you correctly dumping an object with the perl method (there is a bug report #126097 for that). Let us see what happens … Continue reading “🔬49. Dumping 0 but True in Perl 6”
Category: Perl 6 Internals
🔬48. How does ‘0 but True’ work in Perl 6
In Perl 6, you can say 0 but True, and change the result of coercing zero to a Boolean value. (Notice that this is not a string but a valid language construct.) my $v = 0 but True; say $v; # 0 say ?$v; # True Let us see how that works in Rakudo. First … Continue reading “🔬48. How does ‘0 but True’ work in Perl 6”
🔬47. Push-all optimisation of List.roll in Perl 6
Last evening, I made a commit based on my recent observation. Let me devote today’s post to that. In the last few days, we were talking about the two methods for getting random elements from a list — pick and roll. When you pass an integer to the methods, both of them internally use an … Continue reading “🔬47. Push-all optimisation of List.roll in Perl 6”
🔬46. How does ‘pick’ return unique elements (Exploring the pick and the roll methods in Perl 6, part 3)
Yesterday, we went through the code of the roll($N) method, so it will be easier to examine its brother, pick(N$). The code lives in src/core/List.pm: multi method pick(List:D: $number is copy) { fail X::Cannot::Lazy.new(:action(‘.pick from’)) if self.is-lazy; my Int $elems = self.elems; return () unless $elems; $number = nqp::istype($number,Whatever) || $number == Inf ?? $elems !! … Continue reading “🔬46. How does ‘pick’ return unique elements (Exploring the pick and the roll methods in Perl 6, part 3)”
🔬45. Exploring the pick and the roll methods in Perl 6, part 2
Today, we continue examining the internals of the pick and roll methods. Yesterday, we discovered how they work without arguments. It is time to see what the methods do to return multiple values. We start with roll, as it is simpler as it does not care about returning unique elements. The roll($N) is a separate multi-sub with quite … Continue reading “🔬45. Exploring the pick and the roll methods in Perl 6, part 2”
🔬44. Exploring the pick and the roll methods in Perl 6, part 1
Today, we’ll take a look at the implementation of the pick and roll methods. First, a reminder of how they work. The User story If called without arguments, the methods return a random element from a list (or an array, for example): my @a = ‘a’ .. ‘z’; say @a.pick; # b say @a.roll; # … Continue reading “🔬44. Exploring the pick and the roll methods in Perl 6, part 1”
🔬43. Variable $y not declared. Did you mean $x?
One of the additional user-friendly features of Perl 6 is its great error reporting. It is not a mandatory part of the language grammar or semantics, but it really helps a developer to fix the errors in the code. Run the following program: $ perl6 -e’my $var1; say $var2′ It leads to a compile-time error: … Continue reading “🔬43. Variable $y not declared. Did you mean $x?”
🔬42. Mathematics in the Num data type in Perl 6
The first full month of Perl 6 blogging is over. Daily Perl 6 insights of perl6.online: And a sister story of perl6.ru, where I write about the ‘user-level’ elements of Perl 6. My original plan was to have the whole year of posts, so about 1/12 is done. Let us look at the Num class, specifically … Continue reading “🔬42. Mathematics in the Num data type in Perl 6”
🔬41. Converting Num to Rat in Perl 6
In Perl 6, you can easily coerce numerical values from one type to another. One of the interesting conversions is Num to Rat. For example, take the value of π and convert it to a fraction: $ perl6 -e’say pi.Rat.perl’ <355/113> Indeed, 355/113 is 3.14159292035398, which is close to π. The default maximum error is built-in in … Continue reading “🔬41. Converting Num to Rat in Perl 6”
🔬40. Substitution and balanced brackets in Perl 6 regexes
I was randomly looking at different Rakudo Perl 6 source files and found a syntax construction that I could not recognise. I hope you were reading the documentation more carefully (or you did not forget after you have read it) than me, but nevertheless let me devote today’s post to that feature. So, this was … Continue reading “🔬40. Substitution and balanced brackets in Perl 6 regexes”
🔬39. Experimenting with Rats and Nums in Perl 6
Today, it will be a post with some small things about the two data types, Rat and Num. First of all, Zoffix Znet added some insights on Twitter regarding my previous posts. Let me just quote them here. Some useful information about DIVIDE_NUMBERS and DON’T_DIVIDE_NUMBERS: FWIW, these will be gone some time these year, together … Continue reading “🔬39. Experimenting with Rats and Nums in Perl 6”
🔬38. To divide or not to divide
We have seen the mysterious DIVIDE_NUMBERS function a couple of times already. Let us keep our focus on it today. The function is a part of the Rat data type. It lives in src/core/Rat.pm together with its sister, DON’T_DIVIDE_NUMBERS. (An apostrophe is a valid character for identifiers in Perl 6; it is not a namespace separator … Continue reading “🔬38. To divide or not to divide”
🔬37. Dividing by zero in Perl 6
You might already know that it is possible to divide by zero in Perl 6 🙂 Well, seriously speaking, you can only do that until you don’t want to announce it to the others. So, the division itself is not a problem: $ ./perl6 -e’my $x = 1; my $y = $x / 0; say … Continue reading “🔬37. Dividing by zero in Perl 6”
🔬36. Rakudo 2018.01
A new release of Rakudo was just announced. Most of the changes increase Perl 6 performance this time. Let us briefly look at some of them. I am happy to tell that my blog initiated at least two of the changes. Removed UInt64 (not to be confused with uint64) [cf154355] We’ve seen this class in the … Continue reading “🔬36. Rakudo 2018.01”
🔬35. Statement in the Grammar of Perl 6
At the beginning of the year, we began reading Perl 6’s Grammar. That exercise is very interesting but not that easy. Today, let us take one more step and look at the statement. The statement token is relatively compact. It is reproduced here with some simplifications (refer to src/Perl6/Grammar.nqp for the full code): token statement($*LABEL = … Continue reading “🔬35. Statement in the Grammar of Perl 6”
🔬34. Delimiters of embedded comments in Perl 6
In Perl 6, you can leave a comment inside the line of code using the #`(…) syntax: my Int #`(Integer variable) $i = #`(initialising the variable) 42; say #`( Printing it ) $i; This program is equivalent to the following: my Int $i = 42; say $i; The body of the embedded comment is located … Continue reading “🔬34. Delimiters of embedded comments in Perl 6”
🔬33. The cmp infix in Perl 6
In Perl 6, there is an infix operator called cmp. Despite its simple name and some connotations with its counter partner in Perl 5, its semantic is not trivial. From the documentation, we read: Generic, “smart” three-way comparator. Compares strings with string semantics, numbers with number semantics, Pair objects first by key and then by value … Continue reading “🔬33. The cmp infix in Perl 6”
💡32. It’s time for optimism
Today, we will not talk about the internals of Rakudo, NQP, or MoarVM; let me pause for a bit and talk about some random things related to Perl 6 and its future. Efficiency If you follow my blog, I have an update to the post about optimising MoarVM, and it appears that when making calculations … Continue reading “💡32. It’s time for optimism”
🔬31. The opcode dispatching loop in MoarVM
Let me make some correction work following the previous post. I felt that something escaped from my view because changing the code did not bring any advances in speed. Jonathan Worthington left a brilliant comment saying that I was trying to optimise the JIT compiler. Bang! Indeed, I thought that JIT should have had some … Continue reading “🔬31. The opcode dispatching loop in MoarVM”
🔬30. How I was optimising MoarVM
A Friday story for your pleasure. An attentive reader could notice yesterday that MoarVM is using many switch/case choices when it processes the bytecode. In src/jit/graph.c, there is code which returns the address of the function corresponding to the given opcode: static void * op_to_func(MVMThreadContext *tc, MVMint16 opcode) { switch(opcode) { case MVM_OP_checkarity: return MVM_args_checkarity; … Continue reading “🔬30. How I was optimising MoarVM”