Archive
Conditional whenever
I wrote a script to filter iostat because the latter either displays too much or too little. It also doesn’t know about bcache. I wanted to have the script react the same way to pressing q then top
, atop
or iotop
. But it should only watch the keyboard and quit when $*OUT
is a terminal. First we need to read the keyboard.
whenever key-pressed(:!echo) {
when 'q' | 'Q' { done }
}
Now we got a few options to add a check for an attached terminal
if $*OUT.t {
whenever key-pressed(:!echo) {
when 'q' | 'Q' { done }
}
}
$*OUT.t && do whenever key-pressed(:!echo) {
when 'q' | 'Q' { done }
}
do whenever key-pressed(:!echo) {
when 'q' | 'Q' { done }
} if $*OUT.t
The last one kind of lines up with other whenever
blocks but the condition gets harder to read. At first I thought it wont be possible to use ?? !!
because whenever
always wants to run .tap
on the parameter. But then I remembered that we use 0x90 to tell a CPU to do nothing. If we get a Supply
that does nothing we can opt out of doing something.
constant NOP = Supplier.new;
whenever $*OUT.t ?? key-pressed(:!echo) !! NOP {
when 'q' | 'Q' { done }
}
Now it neatly lines up with other whenever
blocks.
As a member of the Perl family Perl 6 has more then one way to do it. Most of them look a big odd though.
I like Rakudo 100x
One of my scripts stopped working without any change by my hands with a most peculiar error message:
Type check failed in binding to parameter '$s'; expected Str but got Int (42)
in sub jpost at /home/bisect/.perl6/sources/674E3526955FCB738B7B736D9DBBD3BD5B162E5C (WWW) line 9
in block <unit> at wrong-line-or-identifier.p6 line 3
Whereby line 9 looks like this:
@stations = | jpost "https://www.perl6.org", :limit(42);
Rakudo is missing the parameter $s
and so am I. Because neither my script nor any routine in WWW
does contain it. This is clearly a regression on a rather simple piece of code and in a popular module. Since I didn’t check that script for quite some time I can’t easily tell what Rakudo commit caused it.
In #perl6 we got bisectable6, a member of the ever growing army of useful bots. Yet it could not help me because it doesn’t come with the community modules installed. Testing against a few dozen Rakudo versions by hand was out of question. So I mustered the little bash-foo I have and wrote a few scripts to build Rakudos past. This resulted in #2779.
If you wish to go on a bug hunt for time travelers too, clone the scripts, install the modules your script needs and make sure it fails with an exit code greater 0. Then run ./build-head-to-tail.sh <nr-of-commits>
to build as many Rakudos as you like. With ./run-head-to-tail <nr-of-commits> <your-script-name-here>
. Up to the number of cores of the host tests are run in parallel. After a while you get a list of OK
, FAIL
ed and SKIP
ed commits. Any Rakudo commit that fails to build will be SKIP
ed.
Running as root may not work because the modules will be put in the wrong spot by zef
. A single commit will take about 70MB of disk space with little hope for deduplication.
The brave folk who push Perl 5 ever forward have a whole CPAN worth of tests to check if anything breaks while they change the compiler. Our stretch of land is still quite small in comparison but I hope to have helped with testing it better.