SlideShare a Scribd company logo
Perl 6
by example
A talk about
a kind of phylosophy
       of Perl 6
  learning process
proto.perl6.org
Proto is a hyper-
lightweight
dependency tracking
and module
installation system
pls is its
new name
We don’t care
 of all that
What we
do care of are
54
  Perl 6 projects
are on proto.perl6.org
history.back()
2003
perl6.ru
launched
Perl 6 by example
It observed
 the code from
parrot/languages/
 perl6/examples
      folder
Record #15

Example research.
     loop()
mandel.p6
was the most exciting
Perl 6 by example
loop ($y=30; $C = $y*0.1 - 1.5, $y--;) {
   loop ($x=0; $c = $x*0.04 - 2.0, $z=0.0,
   $Z=0.0, $x++ < 75;) {
      loop ($r=$c, $i=$C, $k=0;
      $t = $z*$z - $Z*$Z + $r,
      $Z = 2.0*$z*$Z + $i, $z=$t, $k<112;
      $k++) {
   . . .
................::::::::::::::::::::::::::::::::::::::::::::...............
...........::::::::::::::::::::::::::::::::::::::::::::::::::::::..........
........::::::::::::::::::::::::::::::::::,,,,,,,:::::::::::::::::::.......
.....:::::::::::::::::::::::::::::,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::....
...::::::::::::::::::::::::::,,,,,,,,,,,,;;;!:H!!;;;,,,,,,,,:::::::::::::..
:::::::::::::::::::::::::,,,,,,,,,,,,,;;;;!!/>&*|& !;;;,,,,,,,:::::::::::::
::::::::::::::::::::::,,,,,,,,,,,,,;;;;;!!//)|.*#|>/!;;;;;,,,,,,:::::::::::
::::::::::::::::::,,,,,,,,,,,,;;;;;;!!!!//>|:    !:|//!!;;;;;,,,,,:::::::::
:::::::::::::::,,,,,,,,,,;;;;;;;!!/>>I>>)||I#     H&))>////*!;;,,,,::::::::
::::::::::,,,,,,,,,,;;;;;;;;;!!!!/>H:  #|              IH&*I#/;;,,,,:::::::
::::::,,,,,,,,,;;;;;!!!!!!!!!!//>|.H:                     #I>!!;;,,,,::::::
:::,,,,,,,,,;;;;!/||>///>>///>>)|H                         %|&/;;,,,,,:::::
:,,,,,,,,;;;;;!!//)& :;I*,H#&||&/                           *)/!;;,,,,,::::
,,,,,,;;;;;!!!//>)IH:,        ##                            #&!!;;,,,,,::::
,;;;;!!!!!///>)H%.**           *                            )/!;;;,,,,,::::
                                                          &)/!!;;;,,,,,::::
,;;;;!!!!!///>)H%.**           *                            )/!;;;,,,,,::::
,,,,,,;;;;;!!!//>)IH:,        ##                            #&!!;;,,,,,::::
:,,,,,,,,;;;;;!!//)& :;I*,H#&||&/                           *)/!;;,,,,,::::
:::,,,,,,,,,;;;;!/||>///>>///>>)|H                         %|&/;;,,,,,:::::
::::::,,,,,,,,,;;;;;!!!!!!!!!!//>|.H:                     #I>!!;;,,,,::::::
::::::::::,,,,,,,,,,;;;;;;;;;!!!!/>H:  #|              IH&*I#/;;,,,,:::::::
:::::::::::::::,,,,,,,,,,;;;;;;;!!/>>I>>)||I#     H&))>////*!;;,,,,::::::::
::::::::::::::::::,,,,,,,,,,,,;;;;;;!!!!//>|:    !:|//!!;;;;;,,,,,:::::::::
::::::::::::::::::::::,,,,,,,,,,,,,;;;;;!!//)|.*#|>/!;;;;;,,,,,,:::::::::::
:::::::::::::::::::::::::,,,,,,,,,,,,,;;;;!!/>&*|& !;;;,,,,,,,:::::::::::::
...::::::::::::::::::::::::::,,,,,,,,,,,,;;;!:H!!;;;,,,,,,,,:::::::::::::..
.....:::::::::::::::::::::::::::::,,,,,,,,,,,,,,,,,,,,,,:::::::::::::::....
........::::::::::::::::::::::::::::::::::,,,,,,,:::::::::::::::::::.......
...........::::::::::::::::::::::::::::::::::::::::::::::::::::::..........
history.now()
Perl 6 by example
The method:
try to understand
     what you
don’t understand
You’ll find
impressive things
mandelbrot project

 Mandelbrot set
    in Perl 6
my $height = @*ARGS[0] // 31;
my $width = $height;
my $max_iterations = 50;

my $upper-right = -2 + (5/4)i;
my $lower-left = 1/2 - (5/4)i;
my $height = @*ARGS[0] // 31;
my $width = $height;
my $max_iterations = 50;

my $upper-right = -2 + (5/4)i;
my $lower-left = 1/2 - (5/4)i;

Global variable and defined-or
my $height = @*ARGS[0] // 31;
my $width = $height;
my $max_iterations = 50;

my $upper-right = -2 + (5/4)i;
my $lower-left = 1/2 - (5/4)i;

Complex numbers (wow!)
sub mandel(Complex $c) {
  my $z = 0i;
  for ^$max_iterations {
     $z = $z * $z + $c;
     return 1 if ($z.abs > 2);
  }
  return 0;
}
sub mandel(Complex $c) {
  my $z = 0i;
  for ^$max_iterations {
     $z = $z * $z + $c;
     return 1 if ($z.abs > 2);
  }
  return 0;
}
0..$max_iterations range
for subdivide($upper-right.re,
   $lower-left.re, $height) -> $re {
   ...
   (@line, $middle,
    @line.reverse).join(' ').say;
}
for subdivide($upper-right.re,
   $lower-left.re, $height) -> $re {
   ...
   (@line, $middle,
    @line.reverse).join(' ').say;
}


Hyphens in variable names
for subdivide($upper-right.re,
   $lower-left.re, $height) -> $re {
   ...
   (@line, $middle,
    @line.reverse).join(' ').say;
}


for loop and its variable
for subdivide($upper-right.re,
   $lower-left.re, $height) -> $re {
   ...
   (@line, $middle,
    @line.reverse).join(' ').say;
}


Nested method calls
(@line, $middle, @line.reverse).map
({ @color_map[$_] }).join(' ').say;




Method calls on a list
53
Perl 6 projects
    still left
FakeDBI
  and
FakeDBD
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Declaring and defining a class
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Who is the author
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Version number
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Class variables
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


       Not too easy to guess
bash-3.2$ grep '$!' * -r

S02-bits.pod:
  $!foo     object attribute
  private storage
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Twigils indicate private variables
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Class method
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Positional arguments
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Named arguments
class FakeDBI:auth<mberends>:ver<0.0.1> {
   has $!err;
   has $!errstr;
   method connect(
     $dsn, $username, $password,
     :$RaiseError=0, :$PrintError=0,
     :$AutoCommit=1 ) {


 Default values
given $drivername {
    when 'CSV'   {...}
    when 'mysql' { . . . }
    default      {...}
}




 given/when known from Perl 5.10 :-)
52
Perl 6 projects
    still left
Really 52 left?
Much more!
perl6-examples
    on github
cookbook       module-management
doc            parsers
euler          perlmonks
games          shootout
interpreters   tutorial
lib            wsg
perl6-examples
    on github
cookbook       module-management
doc            parsers
euler          perlmonks
games          shootout
interpreters   tutorial
lib            wsg
eulerproject.net
README
    
 
       prob005-unobe.pl
 prob025-polettix.pl
prob001-cspencer.pl
 prob006-polettix.pl
 prob029-polettix.pl
prob001-eric256.pl
 prob007-polettix.pl
 prob052-duff.pl
prob001-hexmode.pl
 prob008-duff.pl
 
 prob053-duff.pl
prob001-unobe.pl 
 prob008-duff2.pl 
 prob063-moritz.pl
prob002-eric256.pl
 prob009-polettix.pl
 prob063-polettix.pl
prob002-hexmode.pl
 prob010-polettix.pl
 prob081-matrix.txt
prob003-eric256.pl
 prob011-moritz.pl prob081-moritz.pl
prob003-hexmode.pl
 prob012-polettix.pl
 prob092-moritz.pl
prob003-lanny.p6 
 prob017-duff.pl
 
 prob104-moritz.pl
prob004-unobe.pl
    prob024-moritz.pl
eulerproject.net
README
    
 
       prob005-unobe.pl
 prob025-polettix.pl
prob001-cspencer.pl
 prob006-polettix.pl
 prob029-polettix.pl
prob001-eric256.pl
 prob007-polettix.pl
 prob052-duff.pl
prob001-hexmode.pl
 prob008-duff.pl
 
 prob053-duff.pl
prob001-unobe.pl 
 prob008-duff2.pl 
 prob063-moritz.pl
prob002-eric256.pl
 prob009-polettix.pl
 prob063-polettix.pl
prob002-hexmode.pl
 prob010-polettix.pl
 prob081-matrix.txt
prob003-eric256.pl
 prob011-moritz.pl prob081-moritz.pl
prob003-hexmode.pl
 prob012-polettix.pl
 prob092-moritz.pl
prob003-lanny.p6 
 prob017-duff.pl
 
 prob104-moritz.pl
prob004-unobe.pl
    prob024-moritz.pl
# A simple implementation
# of Eratosthenes' sieve
sub primes_iterator {
  return sub {
    state %D;
    state $q //= 2;
    $q //= 2;


Again, pure Perl 5.10 :-)
$ perl6 prob007-polettix.pl
===SORRY!===
Symbol '%D' not predeclared in primes_iterator
(prob007-polettix.pl:17)
my %D;
my $q;

# A simple implementation
# of Eratosthenes' sieve
sub primes_iterator {
  return sub {
    #state %D;
    #state $q //= 2;
    $q //= 2;


OK, let’s use global variables this time
$ perl6 prob007-polettix.pl

   . . . Time passed. . .

result: 104743
my $it = primes_iterator();
for 1 .. $nth - 1 -> $i {
  $it();
  say "found $i primes so far" unless $i % 100;
}
say 'result: ', $it();




Subroutine reference in a scalar
51 + ∞
Perl 6 projects
    still left
SVG.pm
my $svg = :svg[
    :width(200), :height(200),
    circle => [
       :cx(100), :cy(100), :r(50)
    ],
    text => [
       :x(10), :y(20), "hello"
    ]
 ];


Hash reference of hash references?
.perl() explains
say $svg.perl;

"svg" => ["width" => 200,
"height" => 200, "circle" =>
["cx" => 100, "cy" => 100, "r"
=> 50], "text" => ["x" => 10,
"y" => 20, "hello"]]
50 + ∞
Perl 6 projects
    still left
Andrew Shitov
talks.shitov.ru | andy@shitov.ru

More Related Content

PDF
I, For One, Welcome Our New Perl6 Overlords
PDF
Perl6 grammars
PDF
The Perl6 Type System
PDF
Perl6 in-production
PDF
The Joy of Smartmatch
PDF
Creating a compiler in Perl 6
PDF
Introdução ao Perl 6
PDF
Perl 6 in Context
I, For One, Welcome Our New Perl6 Overlords
Perl6 grammars
The Perl6 Type System
Perl6 in-production
The Joy of Smartmatch
Creating a compiler in Perl 6
Introdução ao Perl 6
Perl 6 in Context

What's hot (20)

PDF
Learning Perl 6
PDF
Text in search queries with examples in Perl 6
PDF
Learning Perl 6 (NPW 2007)
KEY
Good Evils In Perl (Yapc Asia)
PDF
Perl Bag of Tricks - Baltimore Perl mongers
PDF
Wx::Perl::Smart
PDF
Advanced modulinos trial
PDF
Melhorando sua API com DSLs
PPTX
Electrify your code with PHP Generators
PDF
OSDC.TW - Gutscript for PHP haters
PDF
Perl6 one-liners
PDF
Bag of tricks
PDF
Perl6 Regexen: Reduce the line noise in your code.
PDF
Advanced modulinos
PDF
Descobrindo a linguagem Perl
PDF
Perl 6 for Concurrency and Parallel Computing
PDF
6 things about perl 6
PDF
Debugging: Rules And Tools - PHPTek 11 Version
PPTX
Looping the Loop with SPL Iterators
PDF
The Magic Of Tie
Learning Perl 6
Text in search queries with examples in Perl 6
Learning Perl 6 (NPW 2007)
Good Evils In Perl (Yapc Asia)
Perl Bag of Tricks - Baltimore Perl mongers
Wx::Perl::Smart
Advanced modulinos trial
Melhorando sua API com DSLs
Electrify your code with PHP Generators
OSDC.TW - Gutscript for PHP haters
Perl6 one-liners
Bag of tricks
Perl6 Regexen: Reduce the line noise in your code.
Advanced modulinos
Descobrindo a linguagem Perl
Perl 6 for Concurrency and Parallel Computing
6 things about perl 6
Debugging: Rules And Tools - PHPTek 11 Version
Looping the Loop with SPL Iterators
The Magic Of Tie
Ad

Similar to Perl 6 by example (20)

PPTX
Lecture 3 Perl & FreeBSD administration
PDF
What's New in Perl? v5.10 - v5.16
PDF
Good Evils In Perl
PDF
PDF
Scripting3
ODP
Introduction to Perl - Day 1
PPT
LPW: Beginners Perl
PDF
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
ODP
Devel::hdb debugger talk
PDF
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
ODP
Perl Introduction
PPTX
Perl bhargav
PDF
What we can learn from Rebol?
PDF
Short Introduction To "perl -d"
ODP
Intermediate Perl
PPTX
Perl slid
PDF
tutorial7
PDF
tutorial7
PDF
Utility Modules That You Should Know About
PPT
web programming Unit VI PPT by Bhavsingh Maloth
Lecture 3 Perl & FreeBSD administration
What's New in Perl? v5.10 - v5.16
Good Evils In Perl
Scripting3
Introduction to Perl - Day 1
LPW: Beginners Perl
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Devel::hdb debugger talk
Our Friends the Utils: A highway traveled by wheels we didn't re-invent.
Perl Introduction
Perl bhargav
What we can learn from Rebol?
Short Introduction To "perl -d"
Intermediate Perl
Perl slid
tutorial7
tutorial7
Utility Modules That You Should Know About
web programming Unit VI PPT by Bhavsingh Maloth
Ad

More from Andrew Shitov (20)

PDF
Perl jobs market in 2024, how good is it?
PPTX
Fun with Raspberry PI (and Perl)
PDF
Параллельные вычисления в Perl 6
PDF
AllPerlBooks.com
PDF
YAPC::Europe 2013
PDF
Perl 7, the story of
PDF
Язык программирования Go для Perl-программистов
PDF
Как очистить массив
PDF
What's new in Perl 5.14
PDF
Что нового в Perl 5.14
PDF
There's more than one way to empty it
PDF
How to clean an array
PDF
Perl 5.10 и 5.12
PDF
Say Perl на весь мир
PDF
Personal Perl 6 compiler
PDF
Perl 5.10 in 2010
PDF
Perl 5.10 в 2010-м
PDF
Gearman and Perl
PDF
‎Откуда узнать про Perl 6‎
PDF
‎42 £ в ойрах‎
Perl jobs market in 2024, how good is it?
Fun with Raspberry PI (and Perl)
Параллельные вычисления в Perl 6
AllPerlBooks.com
YAPC::Europe 2013
Perl 7, the story of
Язык программирования Go для Perl-программистов
Как очистить массив
What's new in Perl 5.14
Что нового в Perl 5.14
There's more than one way to empty it
How to clean an array
Perl 5.10 и 5.12
Say Perl на весь мир
Personal Perl 6 compiler
Perl 5.10 in 2010
Perl 5.10 в 2010-м
Gearman and Perl
‎Откуда узнать про Perl 6‎
‎42 £ в ойрах‎

Recently uploaded (20)

PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PDF
Machine learning based COVID-19 study performance prediction
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced Soft Computing BINUS July 2025.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
Electronic commerce courselecture one. Pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Dropbox Q2 2025 Financial Results & Investor Presentation
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
Machine learning based COVID-19 study performance prediction
20250228 LYD VKU AI Blended-Learning.pptx
Unlocking AI with Model Context Protocol (MCP)
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
NewMind AI Monthly Chronicles - July 2025
Advanced Soft Computing BINUS July 2025.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?

Perl 6 by example