6. ThePerlReview•www.theperlreview.com
6ThingsAbout6 # Program execution
BEGIN { put "BEGIN, at compile time, ASAP" }
CHECK { put "CHECK, at compile time, ALAP" }
INIT { put "INIT, during main execution, ASAP" }
END { put "END, during main execution, ALAP" }
for 0 .. 3 -> $item {
my Int $square = $item ** 2;
# Block phasers
ENTER { put "tENTER block" }
LEAVE { put "tLEAVE block" }
KEEP { put "KEEP block: Got value $_" } # NYI
UNDO { put "ttUNDO block" }
PRE { put "PRE block ------" }
POST { put "POST block" }
# Loop phasers
FIRST { put "tFIRST loop" }
NEXT { put "tNEXT loop" }
LAST { put "tLAST loop"; put "**** LOOP is done ****" }
}
https://www.learningperl6.com/2016/11/30/quick-tip-15-phasers/
9. ThePerlReview•www.theperlreview.com
6ThingsAbout6
$ perl6
> my $set_a = set qw/ a b c /;
set(a, c, b)
> my $set_b = set qw/ c d e /;
set(c, e, d)
> $set_a ∪ $set_b
set(a, c, b, e, d)
> $set_a ∩ $set_b
set(c)
> $set_a ∖ $set_b
set(a, b)
> $set_a ⊖ $set_b
set(a, b, e, d)
15. ThePerlReview•www.theperlreview.com
6ThingsAbout6
> my Int %hash{Str}
{}
> %hash{ "Butterflies" } = 137
137
> %hash{ "Llamas" } = "Huh?"
Type check failed in binding to assignval;
expected Int but got Str ("Huh?")
> %hash{ 5 } = 1
Type check failed in binding to key;
expected Str but got Int (5)
16. ThePerlReview•www.theperlreview.com
6ThingsAbout6
my package EXPORT::DEFAULT {
...
subset Pos of Real where * > 0;
subset Neg of Real where * < 0;
subset Zero of Real where * == 0;
subset UNumeric of Real where * >= 0;
subset Even of Int where * % 2 == 0;
subset Odd of Int where * % 2;
}
https://github.com/bradclawsie/Subsets-Common
17. ThePerlReview•www.theperlreview.com
6ThingsAbout6
subset ZInt of Cool is export where {
state ( $min, $max ) =
%names.keys.sort( { $^a <=> $^b } ).[0,*-1];
( $_.truncate == $_ and $min <= $_ <= $max )
or
note "Expected a known atomic number between $min and $max"
and
False;
};
https://github.com/briandfoy/perl6-chemistry-elements