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)”
Month: February 2018
🔬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?”