my @lazy-array = lazy 1, 11, 121 ... 10**100;
say @lazy-array.is-lazy; # OUTPUT: «True»
say @lazy-array[]; # OUTPUT: «[...]»
my @no-longer-lazy = eager @lazy-array; # Forcing eager evaluation
say @no-longer-lazy.is-lazy; # OUTPUT: «False»
say @no-longer-lazy[];
Math!
my \U = 'a'..'z'.Set;
sub postfix:<⁻>(Set $a) { U ⊖ $a }
my @sets;
@sets.push: Set.new( @alphabet.pick( @alphabet.elems.rand))
for @alphabet;
my ($de-Morgan1,$de-Morgan2) = (True,True);
for @sets X @sets -> (\A, \B){
$de-Morgan1 &&= (A ∪ B)⁻ === A⁻ ∩ B⁻;
$de-Morgan2 &&= (A ∩ B)⁻ === A⁻ ∪ B⁻;
}
say "1st De Morgan is ", $de-Morgan1;
say "2nd De Morgan is ", $de-Morgan2;
class Cook {
has @.utensils is rw;
has @.cookbooks is rw;
method cook( $food ) { return "Cooking $food"; }
method clean_utensils {
return "Cleaning $_" for @.utensils;
}
multi method gist(Cook:U:) { '⚗' ~ self.^name ~ '⚗' }
multi method gist(Cook:D:) {
'⚗ Cooks with ' ~ @.utensils.join( " ‣ ") \
~ ' using ' \
~ @.cookbooks.map( "«" ~ * ~ "»").join( " and ") }
}
Ready to serve!
my $cook = Cook.new(
utensils => <spoon ladle knife pan>,
cookbooks => ['Cooking for geeks','The French Chef Cookbook']);
say Cook.gist; # OUTPUT: «⚗Cook⚗»
say $cook.gist;
# OUTPUT: «⚗ Cooks with spoon ‣ ladle ‣ knife ‣ pan using
# «Cooking for geeks» and «The French Chef Cookbook»»