ETOOBUSY 🚀 minimal blogging for the impatient
Idiomatic corrections
TL;DR
gfldex gently provided a more idiomatic approach to Double check a puzzle result
Sadly… under the assumption that I would have understood it.
First things first, read Only infinite elements. This is how Double check a puzzle result should have been coded in an idiomatic way.
I’m in that stage where I honestly have a strong Perl accent (which I like anyway, as I love Perl) and I can’t fully understand people that talk too strict.
For example, I can probably guess what this is for:
(1..6).roll(*)
but I don’t know how to correctly read it. Is it something like take
this list and apply the roll
whatever times you need? If so, why is
the whatever an argument to roll
?
Which, of course, led me to this in the documentation:
multi method roll($n --> Seq)
How nice! So whenever there’s an argument, I can put a whatever and this will generate an infinite lazy list! Let’s put it to the test:
$ raku
...
> sub prova ($n) { return 1 .. $n }
&prova
> my $s = prova(*)
1..Inf
Oooooh!
As a nice side effect, I also got to learn a couple additional things:
- there’s
roll
and there’spick
. In a nutshell, the former just takes values at random and they might be duplicated, while the latter will only give back distinct elements in a single call. - Andrew Shitov wrote a couple of articles on them, 🔬 44. Exploring the pick and the roll methods in Raku, part 1, 🔬45. Exploring the pick and the roll methods in Raku, part 2, and 🔬46. How does ‘pick’ return unique elements (Exploring the pick and the roll methods in Raku, part 3).
Time to read something!