SlideShare a Scribd company logo
Perl6
An Introduction
Perl6
Raku
An Introduction
The nuts and bolts
● Spec tests
○ Complete test suite for the language.
○ Anything that passes the suite is Raku.
The nuts and bolts
● Spec tests
○ Complete test suite for the language.
○ Anything that passes the suite is Raku.
● Rakudo
○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku)
The nuts and bolts
● Spec tests
○ Complete test suite for the language.
○ Anything that passes the suite is Raku.
● Rakudo
○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku)
● MoarVM
○ Short for "Metamodel On A Runtime"
○ Threaded, garbage collected VM optimised for Raku
The nuts and bolts
● Spec tests
○ Complete test suite for the language.
○ Anything that passes the suite is Raku.
● Rakudo
○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku)
● MoarVM
○ Short for "Metamodel On A Runtime"
○ Threaded, garbage collected VM optimised for Raku
● JVM
○ The Java Virtual machine.
The nuts and bolts
● Spec tests
○ Complete test suite for the language.
○ Anything that passes the suite is Raku.
● Rakudo
○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku)
● MoarVM
○ Short for "Metamodel On A Runtime"
○ Threaded, garbage collected VM optimised for Raku
● JVM
○ The Java Virtual machine.
● Rakudo JS (Experimental)
○ Compiles your Raku to a Javascript file that can run in a browser
Multiple Programming Paradigms
What’s your poison?
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
● Object Oriented ?
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
● Object Oriented ?
● Procedural ?
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
● Object Oriented ?
● Procedural ?
● Event Based ?
Multiple Programming Paradigms
What’s your poison?
● Functional Programming ?
● Object Oriented ?
● Procedural ?
● Event Based ?
Raku builds in the concept of the swiss army chainsaw and gives you a toolbox from
which you can build whatever chainsaw you want.
What is truth?
In Raku all of these statements are True:
What is truth?
In Raku all of these statements are True:
1
What is truth?
In Raku all of these statements are True:
1
0.1 + 0.2 - 0.3 == 0
What is truth?
In Raku all of these statements are True:
1
0.1 + 0.2 - 0.3 == 0
1 < 3 > 2
What is truth?
In Raku all of these statements are True:
1
0.1 + 0.2 - 0.3 == 0
1 < 3 > 2
٤٥ == 45 == ߄߅ == ४५
What is truth?
In Raku all of these statements are True:
1
0.1 + 0.2 - 0.3 == 0
1 < 3 > 2
٤٥ == 45 == ߄߅ == ४५
0 but True
Objects, Types and SubSets
● By default Objects are Immutable
○ Useful for both Functional Paradigms and Thread safety
● Both Inheritance and Composition are available and can be mixed
● Roles used for Composition also can be used as Interfaces
● Subsets allow for simple runtime sub type checking
subset SmallInt of Int where * < 50;
sub foo( SmallInt $num ) {
say “*” x $num
}
Multi Dispatch and Signatures
#| Given a user object and a list of preference
#| Return the list of preferences that user has.
sub get-user-preferences( $user, @preferences ) {
die “No User supplied” unless $user:defined;
die “No preferences supplied” unless @preferences;
# If the user has no prefs just return an empty list
# Note calling pref-hash has some overhead...
if ( ! $user.user-has-prefs ) { return (); }
return @preferences.grep( { $user.has-pref($_) } );
}
This is a pretty standard function.
But Raku adds some tools to make
it easier to handle.
Multi Dispatch and Signatures
multi sub get-user-preferences( Any:U $, @ ) {
die “No User supplied”;
}
multi sub get-user-preferences( User $user,
@prefs where ! * ) {
die “No preferences supplied”;
}
multi sub get-user-preferences( User $user, @preferences ) {
# If the user has no prefs just return an empty list
# Note calling pref-hash has some overhead...
if ( ! $user.user-has-prefs ) { return (); }
return @preferences.grep( { $user.has-pref($_) } );
}
Using multi dispatch we can
remove our boilerplate tests
from the start.
We also can add some type
checking as well.
Multi Dispatch and Signatures
multi sub get-user-preferences( User:D $user,
@prefs where ! * ) {
die “No preferences supplied”;
}
multi sub get-user-preferences( User:D $user, @preferences )
{
# If the user has no prefs just return an empty list
# Note calling pref-hash has some overhead...
if ( ! $user.user-has-prefs ) { return (); }
return @preferences.grep( { $user.has-pref($_) } );
}
In fact if we specify we want
a defined user then we can
remove one data check.
The system will raise an
Exception as it can’t find a
matching sub to use.
Multi Dispatch and Signatures
…
multi sub get-user-preferences(
User:D $user where ! *.user-has-prefs, @ ) {
return ();
}
multi sub get-user-preferences( User:D $user, @preferences ) {
return @preferences.grep( { $user.has-pref($_) } );
}
We can also take our
special case out into its
own multi sub.
Multi Dispatch and Signatures
subset UserNoPrefs of User where ! *.user-has-prefs;
…
multi sub get-user-preferences(
UserNoPrefs $, @ ) {
return ();
}
multi sub get-user-preferences( User $user, @preferences ) {
return @preferences.grep( { $user.has-pref($_) } );
}
Finally we can define a subset
of our User class to make the
code easier to read.
Junctions
my @array = ( False, False, False );
my ( $all, $none, $any ) = ( all(@array), none(@array), any(@array) );
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
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
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
# 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 == True;
# all(1,2,3,4,5)
4 < 1&2&3&4&5 < 2 == False;
Promises
“Parallel programming for mortals” or “Basically just like Node”
Promises
“Parallel programming for mortals” or “Basically just like Node”
my $p1 = start { sleep 3; print “Or a simple start? ”; };
Promises
“Parallel programming for mortals” or “Basically just like Node”
my $p1 = start { sleep 3; print “Or a simple start? ”; };
my $p2 = Promise.in(2).then( { print “Why not use a timer? ” } );
Promises
“Parallel programming for mortals” or “Basically just like Node”
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. ” } );
Promises
“Parallel programming for mortals” or “Basically just like Node”
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.” } );
Promises
“Parallel programming for mortals” or “Basically just like Node”
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
“Parallel programming for mortals” or “Basically just like Node”
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
Channels and Supplies
● Channels allow for FIFO messaging between threads
Channels and Supplies
● Channels allow for FIFO messaging between threads
○ Channels can also be treated as lists with data filtering and manipulation being done on the fly
○ Easily fits into a message based data processing paradigm
Channels and Supplies
● Channels allow for FIFO messaging between threads
○ Channels can also be treated as lists with data filtering and manipulation being done on the fly
○ Easily fits into a message based data processing paradigm
● Supplies give event driven responsive messaging
Channels and Supplies
● Channels allow for FIFO messaging between threads
○ Channels can also be treated as lists with data filtering and manipulation being done on the fly
○ Easily fits into a message based data processing paradigm
● Supplies give event driven responsive messaging
○ react / whenever blocks allow for simple handling of events
○ Cro microservice framework built on the concept of chains of supplies from request through layers
of middleware and data processing to response
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
say $á1 ~~ á2;
True
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
say $á1 ~~ á2;
True
say “$á1 : $á2”.uc;
Á : Á
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
say $á1 ~~ á2;
True
say “$á1 : $á2”.uc;
Á : Á
my $ß = 2;
$ß = ( $ß × ¾ )²;
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
say $á1 ~~ á2;
True
say “$á1 : $á2”.uc;
Á : Á
my $ß = 2;
$ß = ( $ß × ¾ )²;
say “ß => $ß”;
ß => 2.25
Unicode
# Single Character
my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”;
my $á2 = “ax301”; # Combining Acute
say “$á1 : $á2”;
á : á
say $á1 ~~ á2;
True
say “$á1 : $á2”.uc;
Á : Á
my $ß = 2;
$ß = ( $ß × ¾ )²;
say “ß => $ß”;
ß => 2.25
say “ß => $ß”.uc;
SS => 2.25
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)
Sets and Bags
my @primes = (1..*).grep( *.is-prime );
my @fib = 1,1,*+*...*;
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 Interface to external libraries
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.
All the other stuff
● Grammars
● Imaginary Numbers
● Proper Exceptions
● CPAN
● Meta Objects
● Telemetry
● IO::Notification
● Date and DateTime built in
● 317 built in types in fact...
● (And so much more)
Further Reading (and Viewing)
● Raku Docs - https://docs.raku.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 - https://www.learningperl6.com/
● Cro - http://cro.services/
● Sparrowdo - https://github.com/melezhik/sparrowdo
● Roles vs Inheritance - https://www.youtube.com/watch?v=cjoWu4eq1Tw
● Perl6 Concurrency - https://www.youtube.com/watch?v=hGyzsviI48M
Questions?

More Related Content

PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
PPT
typemap in Perl/XS
ODP
Advanced Perl Techniques
PDF
Memory Manglement in Raku
KEY
Good Evils In Perl (Yapc Asia)
ZIP
AnyMQ, Hippie, and the real-time web
ODP
How Xslate Works
PPT
On UnQLite
Adding 1.21 Gigawatts to Applications with RabbitMQ (DPC 2015)
typemap in Perl/XS
Advanced Perl Techniques
Memory Manglement in Raku
Good Evils In Perl (Yapc Asia)
AnyMQ, Hippie, and the real-time web
How Xslate Works
On UnQLite

What's hot (20)

PDF
Diving into HHVM Extensions (php[tek] 2016)
PDF
The Ring programming language version 1.7 book - Part 43 of 196
PDF
PL/Perl - New Features in PostgreSQL 9.0
PDF
The Ring programming language version 1.8 book - Part 45 of 202
PPTX
Python Programming Essentials - M8 - String Methods
PPTX
JFokus 50 new things with java 8
PDF
Create your own PHP extension, step by step - phpDay 2012 Verona
PDF
What you need to remember when you upload to CPAN
PDF
Basic NLP with Python and NLTK
PDF
Introduction to Rust
PDF
Top 10 Perl Performance Tips
PPTX
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
ODP
using python module: doctest
PDF
Elegant concurrency
PDF
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
PPT
Working with databases in Perl
PPT
Perl Tidy Perl Critic
PDF
Python高级编程(二)
PDF
Object Trampoline: Why having not the object you want is what you need.
PPTX
Php Extensions for Dummies
Diving into HHVM Extensions (php[tek] 2016)
The Ring programming language version 1.7 book - Part 43 of 196
PL/Perl - New Features in PostgreSQL 9.0
The Ring programming language version 1.8 book - Part 45 of 202
Python Programming Essentials - M8 - String Methods
JFokus 50 new things with java 8
Create your own PHP extension, step by step - phpDay 2012 Verona
What you need to remember when you upload to CPAN
Basic NLP with Python and NLTK
Introduction to Rust
Top 10 Perl Performance Tips
Lean & Mean Tokyo Cabinet Recipes (with Lua) - FutureRuby '09
using python module: doctest
Elegant concurrency
Devel::NYTProf 2009-07 (OUTDATED, see 201008)
Working with databases in Perl
Perl Tidy Perl Critic
Python高级编程(二)
Object Trampoline: Why having not the object you want is what you need.
Php Extensions for Dummies
Ad

Similar to An introduction to Raku (20)

PPT
You Can Do It! Start Using Perl to Handle Your Voyager Needs
ODP
Integrating icinga2 and the HashiCorp suite
PPT
Dealing with Legacy Perl Code - Peter Scott
PPT
Plunging Into Perl While Avoiding the Deep End (mostly)
ODP
What's new in Perl 5.10?
PPT
Training on php by cyber security infotech (csi)
ODP
Advanced Perl Techniques
PPTX
PSGI and Plack from first principles
PDF
An OCaml newbie meets Camlp4 parser
PPTX
Bioinformatica p4-io
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
PPT
Ruby for Perl Programmers
PPT
name name2 n2
PPT
name name2 n
PPT
ppt21
PPT
name name2 n
PPT
ppt17
PPT
ppt7
PPT
ppt9
PPT
test ppt
You Can Do It! Start Using Perl to Handle Your Voyager Needs
Integrating icinga2 and the HashiCorp suite
Dealing with Legacy Perl Code - Peter Scott
Plunging Into Perl While Avoiding the Deep End (mostly)
What's new in Perl 5.10?
Training on php by cyber security infotech (csi)
Advanced Perl Techniques
PSGI and Plack from first principles
An OCaml newbie meets Camlp4 parser
Bioinformatica p4-io
Adding 1.21 Gigawatts to Applications with RabbitMQ (PHPNW Dec 2014 Meetup)
Ruby for Perl Programmers
name name2 n2
name name2 n
ppt21
name name2 n
ppt17
ppt7
ppt9
test ppt
Ad

More from Simon Proctor (10)

PDF
Building a raku module
PDF
Multi stage docker
PPTX
Phasers to stunning
PDF
Perl6 operators and metaoperators
PDF
24 uses for perl6
PDF
Perl 6 command line scripting
PDF
Perl6 signatures, types and multicall
PDF
Perl6 signatures
PPTX
Perl6 a whistle stop tour
PDF
Perl6 a whistle stop tour
Building a raku module
Multi stage docker
Phasers to stunning
Perl6 operators and metaoperators
24 uses for perl6
Perl 6 command line scripting
Perl6 signatures, types and multicall
Perl6 signatures
Perl6 a whistle stop tour
Perl6 a whistle stop tour

Recently uploaded (20)

PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Mushroom cultivation and it's methods.pdf
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Getting Started with Data Integration: FME Form 101
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
WOOl fibre morphology and structure.pdf for textiles
DP Operators-handbook-extract for the Mautical Institute
Unlocking AI with Model Context Protocol (MCP)
Building Integrated photovoltaic BIPV_UPV.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
A comparative analysis of optical character recognition models for extracting...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Hybrid model detection and classification of lung cancer
Mushroom cultivation and it's methods.pdf
TLE Review Electricity (Electricity).pptx
SOPHOS-XG Firewall Administrator PPT.pptx
Zenith AI: Advanced Artificial Intelligence
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
1 - Historical Antecedents, Social Consideration.pdf
Chapter 5: Probability Theory and Statistics
Getting Started with Data Integration: FME Form 101
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
OMC Textile Division Presentation 2021.pptx
Programs and apps: productivity, graphics, security and other tools
WOOl fibre morphology and structure.pdf for textiles

An introduction to Raku

  • 3. The nuts and bolts ● Spec tests ○ Complete test suite for the language. ○ Anything that passes the suite is Raku.
  • 4. The nuts and bolts ● Spec tests ○ Complete test suite for the language. ○ Anything that passes the suite is Raku. ● Rakudo ○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku)
  • 5. The nuts and bolts ● Spec tests ○ Complete test suite for the language. ○ Anything that passes the suite is Raku. ● Rakudo ○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku) ● MoarVM ○ Short for "Metamodel On A Runtime" ○ Threaded, garbage collected VM optimised for Raku
  • 6. The nuts and bolts ● Spec tests ○ Complete test suite for the language. ○ Anything that passes the suite is Raku. ● Rakudo ○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku) ● MoarVM ○ Short for "Metamodel On A Runtime" ○ Threaded, garbage collected VM optimised for Raku ● JVM ○ The Java Virtual machine.
  • 7. The nuts and bolts ● Spec tests ○ Complete test suite for the language. ○ Anything that passes the suite is Raku. ● Rakudo ○ Compiler, compiles Raku to be run on a number of target VM’s (92% written in Raku) ● MoarVM ○ Short for "Metamodel On A Runtime" ○ Threaded, garbage collected VM optimised for Raku ● JVM ○ The Java Virtual machine. ● Rakudo JS (Experimental) ○ Compiles your Raku to a Javascript file that can run in a browser
  • 9. Multiple Programming Paradigms What’s your poison? ● Functional Programming ?
  • 10. Multiple Programming Paradigms What’s your poison? ● Functional Programming ? ● Object Oriented ?
  • 11. Multiple Programming Paradigms What’s your poison? ● Functional Programming ? ● Object Oriented ? ● Procedural ?
  • 12. Multiple Programming Paradigms What’s your poison? ● Functional Programming ? ● Object Oriented ? ● Procedural ? ● Event Based ?
  • 13. Multiple Programming Paradigms What’s your poison? ● Functional Programming ? ● Object Oriented ? ● Procedural ? ● Event Based ? Raku builds in the concept of the swiss army chainsaw and gives you a toolbox from which you can build whatever chainsaw you want.
  • 14. What is truth? In Raku all of these statements are True:
  • 15. What is truth? In Raku all of these statements are True: 1
  • 16. What is truth? In Raku all of these statements are True: 1 0.1 + 0.2 - 0.3 == 0
  • 17. What is truth? In Raku all of these statements are True: 1 0.1 + 0.2 - 0.3 == 0 1 < 3 > 2
  • 18. What is truth? In Raku all of these statements are True: 1 0.1 + 0.2 - 0.3 == 0 1 < 3 > 2 ٤٥ == 45 == ߄߅ == ४५
  • 19. What is truth? In Raku all of these statements are True: 1 0.1 + 0.2 - 0.3 == 0 1 < 3 > 2 ٤٥ == 45 == ߄߅ == ४५ 0 but True
  • 20. Objects, Types and SubSets ● By default Objects are Immutable ○ Useful for both Functional Paradigms and Thread safety ● Both Inheritance and Composition are available and can be mixed ● Roles used for Composition also can be used as Interfaces ● Subsets allow for simple runtime sub type checking subset SmallInt of Int where * < 50; sub foo( SmallInt $num ) { say “*” x $num }
  • 21. Multi Dispatch and Signatures #| Given a user object and a list of preference #| Return the list of preferences that user has. sub get-user-preferences( $user, @preferences ) { die “No User supplied” unless $user:defined; die “No preferences supplied” unless @preferences; # If the user has no prefs just return an empty list # Note calling pref-hash has some overhead... if ( ! $user.user-has-prefs ) { return (); } return @preferences.grep( { $user.has-pref($_) } ); } This is a pretty standard function. But Raku adds some tools to make it easier to handle.
  • 22. Multi Dispatch and Signatures multi sub get-user-preferences( Any:U $, @ ) { die “No User supplied”; } multi sub get-user-preferences( User $user, @prefs where ! * ) { die “No preferences supplied”; } multi sub get-user-preferences( User $user, @preferences ) { # If the user has no prefs just return an empty list # Note calling pref-hash has some overhead... if ( ! $user.user-has-prefs ) { return (); } return @preferences.grep( { $user.has-pref($_) } ); } Using multi dispatch we can remove our boilerplate tests from the start. We also can add some type checking as well.
  • 23. Multi Dispatch and Signatures multi sub get-user-preferences( User:D $user, @prefs where ! * ) { die “No preferences supplied”; } multi sub get-user-preferences( User:D $user, @preferences ) { # If the user has no prefs just return an empty list # Note calling pref-hash has some overhead... if ( ! $user.user-has-prefs ) { return (); } return @preferences.grep( { $user.has-pref($_) } ); } In fact if we specify we want a defined user then we can remove one data check. The system will raise an Exception as it can’t find a matching sub to use.
  • 24. Multi Dispatch and Signatures … multi sub get-user-preferences( User:D $user where ! *.user-has-prefs, @ ) { return (); } multi sub get-user-preferences( User:D $user, @preferences ) { return @preferences.grep( { $user.has-pref($_) } ); } We can also take our special case out into its own multi sub.
  • 25. Multi Dispatch and Signatures subset UserNoPrefs of User where ! *.user-has-prefs; … multi sub get-user-preferences( UserNoPrefs $, @ ) { return (); } multi sub get-user-preferences( User $user, @preferences ) { return @preferences.grep( { $user.has-pref($_) } ); } Finally we can define a subset of our User class to make the code easier to read.
  • 26. Junctions my @array = ( False, False, False ); my ( $all, $none, $any ) = ( all(@array), none(@array), any(@array) );
  • 27. 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
  • 28. 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
  • 29. 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 # 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 == True; # all(1,2,3,4,5) 4 < 1&2&3&4&5 < 2 == False;
  • 30. Promises “Parallel programming for mortals” or “Basically just like Node”
  • 31. Promises “Parallel programming for mortals” or “Basically just like Node” my $p1 = start { sleep 3; print “Or a simple start? ”; };
  • 32. Promises “Parallel programming for mortals” or “Basically just like Node” my $p1 = start { sleep 3; print “Or a simple start? ”; }; my $p2 = Promise.in(2).then( { print “Why not use a timer? ” } );
  • 33. Promises “Parallel programming for mortals” or “Basically just like Node” 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. ” } );
  • 34. Promises “Parallel programming for mortals” or “Basically just like Node” 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.” } );
  • 35. Promises “Parallel programming for mortals” or “Basically just like Node” 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.”;
  • 36. Promises “Parallel programming for mortals” or “Basically just like Node” 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…
  • 38. Channels and Supplies ● Channels allow for FIFO messaging between threads
  • 39. Channels and Supplies ● Channels allow for FIFO messaging between threads ○ Channels can also be treated as lists with data filtering and manipulation being done on the fly ○ Easily fits into a message based data processing paradigm
  • 40. Channels and Supplies ● Channels allow for FIFO messaging between threads ○ Channels can also be treated as lists with data filtering and manipulation being done on the fly ○ Easily fits into a message based data processing paradigm ● Supplies give event driven responsive messaging
  • 41. Channels and Supplies ● Channels allow for FIFO messaging between threads ○ Channels can also be treated as lists with data filtering and manipulation being done on the fly ○ Easily fits into a message based data processing paradigm ● Supplies give event driven responsive messaging ○ react / whenever blocks allow for simple handling of events ○ Cro microservice framework built on the concept of chains of supplies from request through layers of middleware and data processing to response
  • 42. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute
  • 43. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á
  • 44. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á say $á1 ~~ á2; True
  • 45. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á say $á1 ~~ á2; True say “$á1 : $á2”.uc; Á : Á
  • 46. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á say $á1 ~~ á2; True say “$á1 : $á2”.uc; Á : Á my $ß = 2; $ß = ( $ß × ¾ )²;
  • 47. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á say $á1 ~~ á2; True say “$á1 : $á2”.uc; Á : Á my $ß = 2; $ß = ( $ß × ¾ )²; say “ß => $ß”; ß => 2.25
  • 48. Unicode # Single Character my $á1 = “c[LATIN SMALL LETTER A WITH ACUTE]”; my $á2 = “ax301”; # Combining Acute say “$á1 : $á2”; á : á say $á1 ~~ á2; True say “$á1 : $á2”.uc; Á : Á my $ß = 2; $ß = ( $ß × ¾ )²; say “ß => $ß”; ß => 2.25 say “ß => $ß”.uc; SS => 2.25
  • 49. 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)
  • 50. Sets and Bags my @primes = (1..*).grep( *.is-prime ); my @fib = 1,1,*+*...*; 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)
  • 51. Native Call Interface to external libraries 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
  • 52. 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.
  • 53. All the other stuff ● Grammars ● Imaginary Numbers ● Proper Exceptions ● CPAN ● Meta Objects ● Telemetry ● IO::Notification ● Date and DateTime built in ● 317 built in types in fact... ● (And so much more)
  • 54. Further Reading (and Viewing) ● Raku Docs - https://docs.raku.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 - https://www.learningperl6.com/ ● Cro - http://cro.services/ ● Sparrowdo - https://github.com/melezhik/sparrowdo ● Roles vs Inheritance - https://www.youtube.com/watch?v=cjoWu4eq1Tw ● Perl6 Concurrency - https://www.youtube.com/watch?v=hGyzsviI48M

Editor's Notes

  • #3: Give a quick overview of the reasons for the name change.