SlideShare a Scribd company logo
Perl6
A Whistle Stop Tour
Obligatory About Me Slide
Hi.
I’m Simon. (Also known as Scimon in many places)
I write Perl and when I can Perl6.
I’ve been doing it for 15 years and a bit. (Not the Perl6… well)
Now working at Zoopla. We’re hiring, (not sure where we’ll put you…)
Wrote Timer::Breakable, writing more modules.
A Disclaimer
I am still learning Perl6.
It’s a massive powerful language with a lot of scope to create amazing stuff.
Some of the things I say today may be wrong.
This will be because I still don’t fully understand some of the really neat things I’m
playing with.
But all the code examples I give work!
I tested them all.
Humourous Caption Slide
The Year of Linux on the Desktop!
1998, 1999, 2000, 2001, 2002 …
The Year of Perl6 in Production ?
2018...
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
● Object Orientated ?
● Reactive or Event Based ?
● Strongly Typed ?
● Weakly Typed ?
Perl6 builds in the concept of the swiss army chainsaw and gives you a toolbox
from which you can build whatever chainsaw you want.
List::Util
● reduce : [+] @a or @a.reduce(*+*)
● any : so any(@a) > 10
● all : so all(@a) > 10
● none : so none(@a) > 10
● first : @a.first( * > 10 )
● max : @a.max
● maxstr : @a.max( *.Str )
● min : @a.min
● minstr : @a.min( *.Str )
● product : [*] @a or @a.reduce(* * *)
● sum : @a ?? @a.sum !! Nil
● sum0 : @a.sum
● shuffle : @a.pick(@a)
● uniq : @a.unique
● uniqnum : @a.unique( :as( *.Num ) )
● uniqstr : @a.unique( :as( *.Str ) )
Perl6 has Pairs as a Type making the pair methods redundant.
Note that Perl6 is typed and casting a string to a number may raise an exception.
Junctions
my @array = ( False, False, False );
my ( $all, $none, $any ) = ( all(@array), none(@array), any(@array) );
say "All : {$all.so} None: {$none.so} Any: {$any.so}";
All: False None: True Any: False
@array[0] = True;
say "All : {$all.so} None: {$none.so} Any: {$any.so}";
All: False None: False Any: True
4 < 1^2^3^4^5 < 2 == True; # one(1,2,3,4,5)
4 < 1|2|3|4|5 < 2 == True; # any(1,2,3,4,5)
4 < 1&2&3&4&5 < 2 == False; # all(1,2,3,4,5)
Junction Sudoku
my @cells =
[ [ 2, 1, 3, 4 ],
[ 3, 4, 1, 2 ],
[ 2, 3, 4, 1 ],
[ 4, 1, 2, 3 ] ];
my @test-array;
for 0..3 -> $c {
@test-array.push(
one(
(0..3).map(
{
@cells[$c][$_]
}
)
)
);
}
Junction Sudoku
my @cells =
[ [ 2, 1, 3, 4 ],
[ 3, 4, 1, 2 ],
[ 2, 3, 4, 1 ],
[ 4, 1, 2, 3 ] ];
my @test-array;
for 0..3 -> $c {
@test-array.push(
one(
(0..3).map(
{
@cells[$_][$c]
}
)
)
);
}
Junction Sudoku
my @cells =
[ [ 2, 1, 3, 4 ],
[ 3, 4, 1, 2 ],
[ 2, 3, 4, 1 ],
[ 4, 1, 2, 3 ] ];
my @test-array;
for (0,0), (0,2),
(2,0), (2,2) -> ($y, $x) {
@test-array.push(
one(
@cells[$y][$x],
@cells[$y][$x+1],
@cells[$y+1][$x],
@cells[$y+1][$x+1]
)
);
}
Junction Sudoku
my @cells =
[ [ 2, 1, 3, 4 ],
[ 3, 4, 1, 2 ],
[ 2, 3, 4, 1 ],
[ 4, 1, 2, 3 ] ];
{ … Setup Here … }
my $test-all = all( @test-array );
sub test {
? [&&] (1..4).map( * == $test-all );
}
Junction Sudoku (Complete)
my @cells = [ [ 2, 1, 3, 4 ],
[ 3, 4, 1, 2 ],
[ 2, 3, 4, 1 ],
[ 4, 1, 2, 3 ] ];
my @test-array;
for (0,0), (0,2), (2,0), (2,2) -> ($y, $x) {
@test-array.push(
one( @cells[$y][$x], @cells[$y][$x+1],
@cells[$y+1][$x], @cells[$y+1][$x+1] ) );
}
for 0..3 -> $c {
@test-array.push(
one( (0..3).map( { @cells[$c][$_] } ) ) );
@test-array.push(
one( (0..3).map( { @cells[$_][$c] } ) ) );
}
my $test-all = all( @test-array );
sub test {
so [&&] (1..4).map( * == $test-all );
}
sub output {
@cells.map( *.join( " " ) ).join( "n" ).say;
}
output();
say test() ?? "Valid" !! "Invalid";
( @cells[0][0], @cells[0][1] ) =
( @cells[0][1], @cells[0][0] );
output();
say test() ?? "Valid" !! "Invalid";
Promises
“Asynchronous programming for mortals” or “No more callback hell”
my $p1 = start { sleep 3; print “Or a simple start? ”; };
my $p2 = Promise.in(2).then( { print “Why not use a timer? ” } );
my $p3 = Promise.anyof( $p1, $p2 ).then( { print “Something is done. ” } );
my $p4 = Promise.allof( $p1, $p2, $p3 ).then( { print “All the promises done.” } );
print “Promises Begun… ”;
await( $p1, $p2, $p3, $p4 );
say “All done.”;
Promises Begun… Why not use a timer? Something is done. Or a simple start? All the
promises done. All done.
With some pauses…
Channels and Supplies
constant children = 8;
sub MAIN( Str $text ) {
my $dir-channel = Channel.new();
my $file-channel = Channel.new();
my @readers;
for (^8) -> $idx {
@readers[$idx] = Promise.new();
my $sup = $file-channel.Supply.map( -> $path {
my @a = $path.lines.grep( {
defined $_.index($text)
} ); $path => @a
} ).tap( -> $data {
for $data.value { say("{$data.key} : {$_}") }
}, done => { @readers[$idx].keep } );
}
for dir( "." ) -> $p { $dir-channel.send($p) };
loop {
if $dir-channel.poll -> $path {
if ( $path.d ) {
$dir-channel.send( $_ )
for dir( $path )
} elsif ( $path.f ) {
$file-channel.send( $path );
}
} else {
$dir-channel.close;
$file-channel.close;
last;
}
}
await( @readers );
}
Channels and Supplies (Feeds : Secret Sauce)
my $sup = $file-channel.Supply
.map( -> $path {
my @a = $path.lines.grep( {
defined $_.index($text)
} ); $path => @a
} )
.tap( -> $data {
for $data.value { say("{$data.key} : {$_}") }
}, done => { @readers[$idx].keep } );
Sequences, Lazy Evaluation and Rational Numbers
my @primes = (1..*).grep( *.is-prime );
my @evens = 2,4,6...*;
my @fib = 1, 1, * + * ... *;
my $div0 = 42 / 0;
say $div0.nude; # NU(merator and) DE(nominator)
(42 0)
say 0.2 + 0.1 - 0.3 == 0; True
Sets and Bags
my @primes = (1..*).grep( *.is-prime );
my @fib = 1,2,*+*...*;
my $prime-set = set( @primes[0..50] );
say $_, " prime? ", $_ ∈ $prime-set
for @fib[0..5];
say $prime-set ∩ @fib[0..10];
(elem) and ∈ are synonyms as are (&) and ∩
Note : Set operators auto coerce their args to
Sets.
1 prime? False
2 prime? True
3 prime? True
5 prime? True
8 prime? False
13 prime? True
set(13 2 3 5 89)
Native Call
use Cairo;
given Cairo::Image.create(Cairo::FORMAT_ARGB32, 128, 128) {
given Cairo::Context.new($_) {
for 1..16 -> $x {
for 1..16 -> $y {
.rgb($x/16, $y/16, 0 );
.rectangle( 8 * ( $x - 1), 8 * ( $y - 1 ), 8 , 8 );
.fill;
}
}
};
.write_png("test2.png")
}
https://github.com/timo/cairo-p6
NativeCall (A peek inside)
method write_to_png(Str $filename)
returns int32
is native($cairolib)
is symbol('cairo_surface_write_to_png') {*}
method rectangle(num64 $x, num64 $y, num64 $w, num64 $h)
is native($cairolib)
is symbol('cairo_rectangle') {*}
That simple. Here $cairolib is either 'libcairo-2' or ('cairo', v2)
depending on the architecture.
Roles
Yeah you know roles right? Well what about this?
role logger {
method log-msg ( Str $msg ) { say “{$msg} : {self.perl}” }
};
my $num = 5;
$num.?log-msg( "Not a logger" );
$num does logger;
$num.?log-msg( "Loggable" );
Or
my $result = 0 but True;
Unicode
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; # Smart Quotes!
my $á2 = “ax301”;
say “$á1 : $á2”;
á : á
say $á1 eq á2;
True
say “$á1 : $á2”.uc;
Á : Á
my $æ = 2;
$æ = ( $æ * ¾ )²;
say “æ => $æ”;
æ => 2.25
All the other stuff
● Grammars
● Imaginary Numbers
● Proper Exceptions
● CPAN
● Meta Objects
● Telemetry
● JVM
● RakudoJS
● IO::Notification
● Date and DateTime built in
● (And so much more)
Further Reading (and Viewing)
● Perl 6 Docs - https://docs.perl6.org/
● High End Unicode in Perl 6 - https://youtu.be/Oj_lgf7A2LM
● Perl6 Superglue for the 21st Century - https://www.youtube.com/watch?v=q8stPrG1rDo
● Think Perl 6 - http://greenteapress.com/wp/think-perl-6/
● Using Perl 6 - https://deeptext.media/using-perl6
● Learning Perl 6 (On the Way) - https://www.learningperl6.com/
● Cro - http://cro.services/
● Bailador - https://github.com/Bailador/Bailador
● Sparrowdo - https://github.com/melezhik/sparrowdo
● Spitsh - https://github.com/spitsh/spitsh
● Roles vs Inheritance - https://www.youtube.com/watch?v=cjoWu4eq1Tw
Questions?

More Related Content

What's hot

Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
ikdysfm
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
Pete McFarlane
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
XSolve
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
brian d foy
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
Paulo Morgado
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
osfameron
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
Susan Potter
 
Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6
Paulo Morgado
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
Patrick Allaert
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
Suyeol Jeon
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
UC San Diego
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
Nikita Popov
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
Ryan McGeary
 
Building fast interpreters in Rust
Building fast interpreters in RustBuilding fast interpreters in Rust
Building fast interpreters in Rust
Ingvar Stepanyan
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
JangHyuk You
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Codestasimus
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureMike Fogus
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
Nikita Popov
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
Saeid Zebardast
 

What's hot (19)

Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
How to write code you won't hate tomorrow
How to write code you won't hate tomorrowHow to write code you won't hate tomorrow
How to write code you won't hate tomorrow
 
Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
 
The Magic Of Tie
The Magic Of TieThe Magic Of Tie
The Magic Of Tie
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Haskell in the Real World
Haskell in the Real WorldHaskell in the Real World
Haskell in the Real World
 
Functional Algebra: Monoids Applied
Functional Algebra: Monoids AppliedFunctional Algebra: Monoids Applied
Functional Algebra: Monoids Applied
 
Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6Tuga it 2016 - What's New In C# 6
Tuga it 2016 - What's New In C# 6
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
RxSwift 시작하기
RxSwift 시작하기RxSwift 시작하기
RxSwift 시작하기
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Building fast interpreters in Rust
Building fast interpreters in RustBuilding fast interpreters in Rust
Building fast interpreters in Rust
 
Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기Programming Lisp Clojure - 2장 : 클로저 둘러보기
Programming Lisp Clojure - 2장 : 클로저 둘러보기
 
Groovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony CodeGroovy vs Boilerplate and Ceremony Code
Groovy vs Boilerplate and Ceremony Code
 
Fertile Ground: The Roots of Clojure
Fertile Ground: The Roots of ClojureFertile Ground: The Roots of Clojure
Fertile Ground: The Roots of Clojure
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
Java Cheat Sheet
Java Cheat SheetJava Cheat Sheet
Java Cheat Sheet
 

Similar to Perl6 a whistle stop tour

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
FITC
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
Lucas Witold Adamus
 
Functional perl
Functional perlFunctional perl
Functional perl
Errorific
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to PerlSway Wang
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
tinypigdotcom
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
Damien Seguy
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
brian d foy
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
brian d foy
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsSunil Kumar Gunasekaran
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
Stoyan Stefanov
 
Scripting3
Scripting3Scripting3
Scripting3Nao Dara
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
Andrew Shitov
 
Php functions
Php functionsPhp functions
Php functions
JIGAR MAKHIJA
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
abrummett
 
20220112 sac v1
20220112 sac v120220112 sac v1
20220112 sac v1
Sharon Liu
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
XSolve
 

Similar to Perl6 a whistle stop tour (20)

Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
An Intro To ES6
An Intro To ES6An Intro To ES6
An Intro To ES6
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Functional perl
Functional perlFunctional perl
Functional perl
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Perl Bag of Tricks - Baltimore Perl mongers
Perl Bag of Tricks  -  Baltimore Perl mongersPerl Bag of Tricks  -  Baltimore Perl mongers
Perl Bag of Tricks - Baltimore Perl mongers
 
PERL for QA - Important Commands and applications
PERL for QA - Important Commands and applicationsPERL for QA - Important Commands and applications
PERL for QA - Important Commands and applications
 
Short intro to ECMAScript
Short intro to ECMAScriptShort intro to ECMAScript
Short intro to ECMAScript
 
JavaScript for PHP developers
JavaScript for PHP developersJavaScript for PHP developers
JavaScript for PHP developers
 
Scripting3
Scripting3Scripting3
Scripting3
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Php functions
Php functionsPhp functions
Php functions
 
The Perl6 Type System
The Perl6 Type SystemThe Perl6 Type System
The Perl6 Type System
 
20220112 sac v1
20220112 sac v120220112 sac v1
20220112 sac v1
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 

More from Simon Proctor

An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
Simon Proctor
 
Building a raku module
Building a raku moduleBuilding a raku module
Building a raku module
Simon Proctor
 
Multi stage docker
Multi stage dockerMulti stage docker
Multi stage docker
Simon Proctor
 
Phasers to stunning
Phasers to stunningPhasers to stunning
Phasers to stunning
Simon Proctor
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
Simon Proctor
 
24 uses for perl6
24 uses for perl624 uses for perl6
24 uses for perl6
Simon Proctor
 
Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scripting
Simon Proctor
 
Perl6 signatures, types and multicall
Perl6 signatures, types and multicallPerl6 signatures, types and multicall
Perl6 signatures, types and multicall
Simon Proctor
 
Perl6 signatures
Perl6 signaturesPerl6 signatures
Perl6 signatures
Simon Proctor
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
Simon Proctor
 

More from Simon Proctor (10)

An introduction to Raku
An introduction to RakuAn introduction to Raku
An introduction to Raku
 
Building a raku module
Building a raku moduleBuilding a raku module
Building a raku module
 
Multi stage docker
Multi stage dockerMulti stage docker
Multi stage docker
 
Phasers to stunning
Phasers to stunningPhasers to stunning
Phasers to stunning
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
 
24 uses for perl6
24 uses for perl624 uses for perl6
24 uses for perl6
 
Perl 6 command line scripting
Perl 6 command line scriptingPerl 6 command line scripting
Perl 6 command line scripting
 
Perl6 signatures, types and multicall
Perl6 signatures, types and multicallPerl6 signatures, types and multicall
Perl6 signatures, types and multicall
 
Perl6 signatures
Perl6 signaturesPerl6 signatures
Perl6 signatures
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

Recently uploaded

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 

Recently uploaded (20)

Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 

Perl6 a whistle stop tour

  • 2. Obligatory About Me Slide Hi. I’m Simon. (Also known as Scimon in many places) I write Perl and when I can Perl6. I’ve been doing it for 15 years and a bit. (Not the Perl6… well) Now working at Zoopla. We’re hiring, (not sure where we’ll put you…) Wrote Timer::Breakable, writing more modules.
  • 3. A Disclaimer I am still learning Perl6. It’s a massive powerful language with a lot of scope to create amazing stuff. Some of the things I say today may be wrong. This will be because I still don’t fully understand some of the really neat things I’m playing with. But all the code examples I give work! I tested them all.
  • 4. Humourous Caption Slide The Year of Linux on the Desktop! 1998, 1999, 2000, 2001, 2002 … The Year of Perl6 in Production ? 2018...
  • 5. Multiple Programming Paradigms What’s your poison? ● Functional Programming ? ● Object Orientated ? ● Reactive or Event Based ? ● Strongly Typed ? ● Weakly Typed ? Perl6 builds in the concept of the swiss army chainsaw and gives you a toolbox from which you can build whatever chainsaw you want.
  • 6. List::Util ● reduce : [+] @a or @a.reduce(*+*) ● any : so any(@a) > 10 ● all : so all(@a) > 10 ● none : so none(@a) > 10 ● first : @a.first( * > 10 ) ● max : @a.max ● maxstr : @a.max( *.Str ) ● min : @a.min ● minstr : @a.min( *.Str ) ● product : [*] @a or @a.reduce(* * *) ● sum : @a ?? @a.sum !! Nil ● sum0 : @a.sum ● shuffle : @a.pick(@a) ● uniq : @a.unique ● uniqnum : @a.unique( :as( *.Num ) ) ● uniqstr : @a.unique( :as( *.Str ) ) Perl6 has Pairs as a Type making the pair methods redundant. Note that Perl6 is typed and casting a string to a number may raise an exception.
  • 7. Junctions my @array = ( False, False, False ); my ( $all, $none, $any ) = ( all(@array), none(@array), any(@array) ); say "All : {$all.so} None: {$none.so} Any: {$any.so}"; All: False None: True Any: False @array[0] = True; say "All : {$all.so} None: {$none.so} Any: {$any.so}"; All: False None: False Any: True 4 < 1^2^3^4^5 < 2 == True; # one(1,2,3,4,5) 4 < 1|2|3|4|5 < 2 == True; # any(1,2,3,4,5) 4 < 1&2&3&4&5 < 2 == False; # all(1,2,3,4,5)
  • 8. Junction Sudoku my @cells = [ [ 2, 1, 3, 4 ], [ 3, 4, 1, 2 ], [ 2, 3, 4, 1 ], [ 4, 1, 2, 3 ] ]; my @test-array; for 0..3 -> $c { @test-array.push( one( (0..3).map( { @cells[$c][$_] } ) ) ); }
  • 9. Junction Sudoku my @cells = [ [ 2, 1, 3, 4 ], [ 3, 4, 1, 2 ], [ 2, 3, 4, 1 ], [ 4, 1, 2, 3 ] ]; my @test-array; for 0..3 -> $c { @test-array.push( one( (0..3).map( { @cells[$_][$c] } ) ) ); }
  • 10. Junction Sudoku my @cells = [ [ 2, 1, 3, 4 ], [ 3, 4, 1, 2 ], [ 2, 3, 4, 1 ], [ 4, 1, 2, 3 ] ]; my @test-array; for (0,0), (0,2), (2,0), (2,2) -> ($y, $x) { @test-array.push( one( @cells[$y][$x], @cells[$y][$x+1], @cells[$y+1][$x], @cells[$y+1][$x+1] ) ); }
  • 11. Junction Sudoku my @cells = [ [ 2, 1, 3, 4 ], [ 3, 4, 1, 2 ], [ 2, 3, 4, 1 ], [ 4, 1, 2, 3 ] ]; { … Setup Here … } my $test-all = all( @test-array ); sub test { ? [&&] (1..4).map( * == $test-all ); }
  • 12. Junction Sudoku (Complete) my @cells = [ [ 2, 1, 3, 4 ], [ 3, 4, 1, 2 ], [ 2, 3, 4, 1 ], [ 4, 1, 2, 3 ] ]; my @test-array; for (0,0), (0,2), (2,0), (2,2) -> ($y, $x) { @test-array.push( one( @cells[$y][$x], @cells[$y][$x+1], @cells[$y+1][$x], @cells[$y+1][$x+1] ) ); } for 0..3 -> $c { @test-array.push( one( (0..3).map( { @cells[$c][$_] } ) ) ); @test-array.push( one( (0..3).map( { @cells[$_][$c] } ) ) ); } my $test-all = all( @test-array ); sub test { so [&&] (1..4).map( * == $test-all ); } sub output { @cells.map( *.join( " " ) ).join( "n" ).say; } output(); say test() ?? "Valid" !! "Invalid"; ( @cells[0][0], @cells[0][1] ) = ( @cells[0][1], @cells[0][0] ); output(); say test() ?? "Valid" !! "Invalid";
  • 13. Promises “Asynchronous programming for mortals” or “No more callback hell” my $p1 = start { sleep 3; print “Or a simple start? ”; }; my $p2 = Promise.in(2).then( { print “Why not use a timer? ” } ); my $p3 = Promise.anyof( $p1, $p2 ).then( { print “Something is done. ” } ); my $p4 = Promise.allof( $p1, $p2, $p3 ).then( { print “All the promises done.” } ); print “Promises Begun… ”; await( $p1, $p2, $p3, $p4 ); say “All done.”; Promises Begun… Why not use a timer? Something is done. Or a simple start? All the promises done. All done. With some pauses…
  • 14. Channels and Supplies constant children = 8; sub MAIN( Str $text ) { my $dir-channel = Channel.new(); my $file-channel = Channel.new(); my @readers; for (^8) -> $idx { @readers[$idx] = Promise.new(); my $sup = $file-channel.Supply.map( -> $path { my @a = $path.lines.grep( { defined $_.index($text) } ); $path => @a } ).tap( -> $data { for $data.value { say("{$data.key} : {$_}") } }, done => { @readers[$idx].keep } ); } for dir( "." ) -> $p { $dir-channel.send($p) }; loop { if $dir-channel.poll -> $path { if ( $path.d ) { $dir-channel.send( $_ ) for dir( $path ) } elsif ( $path.f ) { $file-channel.send( $path ); } } else { $dir-channel.close; $file-channel.close; last; } } await( @readers ); }
  • 15. Channels and Supplies (Feeds : Secret Sauce) my $sup = $file-channel.Supply .map( -> $path { my @a = $path.lines.grep( { defined $_.index($text) } ); $path => @a } ) .tap( -> $data { for $data.value { say("{$data.key} : {$_}") } }, done => { @readers[$idx].keep } );
  • 16. Sequences, Lazy Evaluation and Rational Numbers my @primes = (1..*).grep( *.is-prime ); my @evens = 2,4,6...*; my @fib = 1, 1, * + * ... *; my $div0 = 42 / 0; say $div0.nude; # NU(merator and) DE(nominator) (42 0) say 0.2 + 0.1 - 0.3 == 0; True
  • 17. Sets and Bags my @primes = (1..*).grep( *.is-prime ); my @fib = 1,2,*+*...*; my $prime-set = set( @primes[0..50] ); say $_, " prime? ", $_ ∈ $prime-set for @fib[0..5]; say $prime-set ∩ @fib[0..10]; (elem) and ∈ are synonyms as are (&) and ∩ Note : Set operators auto coerce their args to Sets. 1 prime? False 2 prime? True 3 prime? True 5 prime? True 8 prime? False 13 prime? True set(13 2 3 5 89)
  • 18. Native Call use Cairo; given Cairo::Image.create(Cairo::FORMAT_ARGB32, 128, 128) { given Cairo::Context.new($_) { for 1..16 -> $x { for 1..16 -> $y { .rgb($x/16, $y/16, 0 ); .rectangle( 8 * ( $x - 1), 8 * ( $y - 1 ), 8 , 8 ); .fill; } } }; .write_png("test2.png") } https://github.com/timo/cairo-p6
  • 19. NativeCall (A peek inside) method write_to_png(Str $filename) returns int32 is native($cairolib) is symbol('cairo_surface_write_to_png') {*} method rectangle(num64 $x, num64 $y, num64 $w, num64 $h) is native($cairolib) is symbol('cairo_rectangle') {*} That simple. Here $cairolib is either 'libcairo-2' or ('cairo', v2) depending on the architecture.
  • 20. Roles Yeah you know roles right? Well what about this? role logger { method log-msg ( Str $msg ) { say “{$msg} : {self.perl}” } }; my $num = 5; $num.?log-msg( "Not a logger" ); $num does logger; $num.?log-msg( "Loggable" ); Or my $result = 0 but True;
  • 21. Unicode my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; # Smart Quotes! my $á2 = “ax301”; say “$á1 : $á2”; á : á say $á1 eq á2; True say “$á1 : $á2”.uc; Á : Á my $æ = 2; $æ = ( $æ * ¾ )²; say “æ => $æ”; æ => 2.25
  • 22. All the other stuff ● Grammars ● Imaginary Numbers ● Proper Exceptions ● CPAN ● Meta Objects ● Telemetry ● JVM ● RakudoJS ● IO::Notification ● Date and DateTime built in ● (And so much more)
  • 23. Further Reading (and Viewing) ● Perl 6 Docs - https://docs.perl6.org/ ● High End Unicode in Perl 6 - https://youtu.be/Oj_lgf7A2LM ● Perl6 Superglue for the 21st Century - https://www.youtube.com/watch?v=q8stPrG1rDo ● Think Perl 6 - http://greenteapress.com/wp/think-perl-6/ ● Using Perl 6 - https://deeptext.media/using-perl6 ● Learning Perl 6 (On the Way) - https://www.learningperl6.com/ ● Cro - http://cro.services/ ● Bailador - https://github.com/Bailador/Bailador ● Sparrowdo - https://github.com/melezhik/sparrowdo ● Spitsh - https://github.com/spitsh/spitsh ● Roles vs Inheritance - https://www.youtube.com/watch?v=cjoWu4eq1Tw