Tnere's-a.new(:Perl).in-town()

GitHub: JJ, Twitter: @jjmerelo, CPAN: JMERELO

Perl 6 doc cer

3rd in # lines perl6/doc

1st in # issues closed

What is Perl 6

MoarVM + NQP + Rakudo

+ roast

>

Perl 6 has lotsa cool things!

Grammars!

grammar HasOur {
    token TOP {
        :our $our = 'þor';
        $our \s+ is \s+ mighty
    }
}

say HasOur.parse('þor is mighty');
say $HasOur::our;

Async code!

my $fixer = Proc::Async.new('awk', 
    'BEGIN {print "!"} {print "^" gsub(/[\\:]/,"",$0)}', 
    $input-file);

Lazyness!

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;

Smart smartmatch!

my @regex-check = ( /<alnum>/, /<alpha>/, /<punct>/ );
say @regex-check.map: "33af" ~~ *;
# OUTPUT: «(「3」␤ alnum => 「3」 「a」␤ alpha => 「a」 Nil)␤»

A real MOP!

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»␤»

Functional awesomeness!

say [[1, 2, [3, 4]], [[5, 6, [7, 8]]]].duckmap:
   -> $array where .elems == 2 { $array.elems };
# OUTPUT: «[[1 2 2] [5 6 2]]␤» 
method distance( @chromosome --> Rat) {
    my @distances = @!peaks.map: (*.list Z== @chromosome).sum;
    return 1-@distances.min / @chromosome.elems;
}
>

You ain't seen nothin' yet!

>

Threads!

with auto-threading!

multi sub evaluate( :@population,
	            :%fitness-of,
	            :$evaluator,
                    Bool :$auto-t --> Mix ) is export {
    my @unique-population = @population.unique;
    my @evaluations = @unique-population.race(degree => 8)
      .map( { $^p => $evaluator( $^p ) } );
    my MixHash $pop-bag;
    for @evaluations -> $pair {
        $pop-bag{$pair.key.item} = $pair.value;
    }
    return $pop-bag.Mix;
}
>

Full

and fast

Unicode!

my @result =(
    <TWO THREE FOUR FIVE SEVEN> »~» " " X~ <FIFTHS SIXTHS EIGHTHS>
    ==> map( {"VULGAR FRACTION " ~ $^þ } )
    ==> grep({ .uniparse })
    ==> map( { .uniparse} );
);
[⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
[⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
[⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
[⅖ ⅗ ⅜ ⅘ ⅚ ⅝ ⅞]
		 

Check Perl 6 out now!

Thanks for listening!