🔬55. FatRat vs Rat in Perl 6

Yesterday, Solomon Foster posted an example in the Perl 6 group on Facebook: my @x = FatRat.new(1, 1), -> \$x { \$x – (\$x ** 2 – \$N) / (2 * \$x) } … * This code implements Newton’s method of finding an approximate value of a square root of \$N. The important thing is … Continue reading “🔬55. FatRat vs Rat in Perl 6”

Perl 6 Grammars, Part 1

Originally published on perl.com The Perl 6 language has builtin support of grammars. You may consider grammars as a combination of the well known regular expressions and utilities such as yacc or bison, or more sophisticated grammar tools such as ANTLR. All that—both lexer, parser, and also semantic processing—which are often separate parts of compilers, is built-in and available … Continue reading “Perl 6 Grammars, Part 1”

🔬54. Going over the Bridge, part 2. Let’s get rid of it

Today, we continue working with the Bridge method in Rakudo Perl 6. Yesterday, we saw the definitions of the methods in a few pre-defined data types. It is time to see how the method is used. What’s inside? The major use of the method is inside the Real role, which contains the following set of methods: … Continue reading “🔬54. Going over the Bridge, part 2. Let’s get rid of it”

🔬53. Going over the Bridge, part 1

In the classes that handle numbers in Perl 6, we saw the Bridge method, which is used polymorphically. Let us spend some time and try to understand 1) how it works and 2) is it necessary. Classes and Roles Our first step is to look where the method is defined. Here is the list of … Continue reading “🔬53. Going over the Bridge, part 1”

🔬52. An attempt to understand how [*] works in Perl 6

Reduction operators are one of the many attractive features of Perl 6. A classical example is calculating factorial: say [*] 1..5; # 120 It is remarkable that in the AST output (generated with the –target=ast command-line option) you do not see any cycles. There is the METAOP_REDUCE_LEFT call, and obviously, the rest is hidden on the deeper … Continue reading “🔬52. An attempt to understand how [*] works in Perl 6”

🔬51. Colonpair in Perl 6’s Grammar, part 2

Today, we continue examining the colonpair syntax in Perl 6 and will give an addition to the third branch of the token. Here’s the branch we are looking at today: # branch 3 | <identifier> { \$*key := \$<identifier>.Str; } [ || <.unsp>? :dba(‘pair value’) <coloncircumfix(\$*key)> { \$*value := \$<coloncircumfix>; } || { \$*value := 1; … Continue reading “🔬51. Colonpair in Perl 6’s Grammar, part 2”

🔬50. Colonpair in Perl 6’s Grammar, part 1

Welcome to the 50th post in this series! Today, we’ll talk about a small syntax construction, which is nevertheless is quite complicated in terms of Grammar. Let us look at the whole colonpair token first: token colonpair { :my \$*key; :my \$*value; ‘:’ :dba(‘colon pair’) [ | ‘!’ [ <identifier> || <.panic: “Malformed False pair; … Continue reading “🔬50. Colonpair in Perl 6’s Grammar, part 1”

🔬49. Dumping 0 but True in Perl 6

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”

🔬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”