Perl 6 - Oktiva

whooploafSoftware and s/w Development

Dec 13, 2013 (3 years and 8 months ago)

113 views



Perl 6


Perl 6
The quest for the holy grail


Perl 6
or


Perl 6
Why are we working for 9 years
and are still excited about it


A bit of history
Perl was always different


A bit of history
To great extent, because of this guy:


Who is Larry Wall
He became more famous for
being the author of Perl


Who is Larry Wall
But in fact, he is one of the people that more
invested in the social aspects
of computer programming.


Who is Larry Wall
Larry Wall wrote “rn”, one of the more
used newsgroup reader in the
usenet era.


Who is Larry Wall
Larry Wall wrote “patch”,
that changed the way people
share code.


Who is Larry Wall
It was the person who bet in the idea that a
programming language is not different
than any human language.


The Perl idiom
open my $file, 'test.txt' or die 'bummer'


The Perl idiom
next unless $x eq 'bad'


The Perl idiom
foreach my $i (1..10) { print $i }


The Perl idiom
As every idiom, Perl has
accents and dialects


The Perl idiom
Schwartzian Transform
@sorted = map  { $_­>[0] }
          
sort { $a­>[1] cmp $b­>[1] }
          
map  { [$_, foo($_)] }
               
@unsorted;


The Perl idiom
my %a = (a => 1, b => 2);
my %b = reverse %a;


The Perl idiom
Class::Accessor
Moose
bless {}, $class
Mouse


The coffee mug incident
Everything was going fine, CPAN had thousands
of modules, the community was tighter and closer,
but we needed sometihng new,
something exciting.


The coffee mug incident
It took Jon Orwant throwing
coffee mugs in the wall...
and there were about 20 of us in the room, and he
picks up a coffee mug and throws it against the
other wall and he keeps throwing coffee mugs
against the other wall, and he says "we are
fucked unless we can come up with something
that will excite the community, because
everyone's getting bored and going off and doing
other things”


And that was how Perl 6 born,
in 2000
And so came the RFCs

Perl 6 is a community rewrite of Perl”


And that was how Perl 6 born
Then the Apocalypses


And that was how Perl 6 born
Then the Exegesis


And that was how Perl 6 born
And, finally, came the Synopsis


Perl 6
Perl 6 is an specification and
a test suite.
Any implementation that follows that spec and
pass the tests can be called Perl 6.


Perl 6 Implementations
Damian Conway started writing a set of modules
bringing Perl 6 features to Perl 5
Perl6::Variables
Perl6::Form
Perl6::Gather


Perl 6 Implementations
Then came Parrot, which would be the virtual
machine to rule them all (before .Net CLR)


Perl 6 Implementations
Then came FP6 and pugs,
with Audrey's -Ofun


Perl 6 Implementations
With the -Ofun, a new spirit was found


-Ofun
pugs-perl5


-Ofun
pugs-perl5, Moose


-Ofun
pugs-perl5, Moose, LREP


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6, Elf


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6, Elf, gimme5


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6, Elf, gimme5,
STD


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6, Elf, gimme5,
STD, smop


-Ofun
pugs-perl5, Moose, LREP, Pugs::Compiler::Rule,
v6-alpha, MiniPerl6, KindaPerl6, Elf, gimme5,
STD, smop, mildew


Perl 6 Implementations
In the meanwhile, the Perl 6 on Parrot
implementation also takes shape,
and gets the name Rakudo


Nowadays
STD is the official Perl 6 grammar
Rakudo é the Perl 6 on Parrot implementation
Mildew is the Perl 6 on SMOP implementation
(that should be key to perl5 interoperation)


Amazing Perl 6
Perl 6 is a language with so many new features,
that no currently existing virtual machine can
provide all the needed semantics.


Amazing Perl 6
Perl 6 tries even harder to amplify the social
perspecitive, allowing the user to completely
customize the language.


Amazing Perl 6
# compact and expressive
say “Hello World”


Amazing Perl 6
# chained operators
if 4 < $x < 10 { ... }


Amazing Perl 6
# object orientation
class Foo {
has $.bar;
method baz { ... }
}


Amazing Perl 6
# new concepts in object orientation
class Dog {

has $.name;
}
role Barf {

method bark {

say “$.name barked!”

}
}
my $x = Dog.new;
$x does Barf;
$x.bark;


Amazing Perl 6
# new concepts in object orientation
my $x = 0 but True;
if $x { say “Success!” };


Amazing Perl 6
# meta-object orientation
Dog.^add_method(...)
Cat.^dispatch(...)


Amazing Perl 6
# junctions
if $dice == 7 | 11 { say 'Ganhou!' }
elsif $dice == 2 | 3 | 12 { say 'Perdeu!'}


Amazing Perl 6
# user-defined operators
multi prefix:<√> { sqrt($^x) }
say √25;


Amazing Perl 6
# operator overload
multi infix:<+> ($a where 2, $b where 2) { 5 }
say 2 + 2; # 5


Amazing Perl 6
# meta-operators
say [+] 1, 2, 3, 4, 5;


Amazing Perl 6
# mutable grammar
say “This is Perl 6 code!”
{

use java;

System.out.println(“This is Java Code!”);
}


Amazing Perl 6
# CPAN compatibility
use CGI:from<perl5>;


Amazing Perl 6
# lazy lists
my @a = gather for ^Inf {

take “This is number $^i”;
};
say @a[10];


Amazing Perl 6
# lazy lists and generators
my @fibonacci = 1, 1 ... { $^a + $^b }
say @fibonacci[6]; # 13


Amazing Perl 6
A more concrete example,
a RPN Calculator in Perl 6


multi infix:<rpn> (@stack, $num where /^ \d+[\.\d+]? $/) {

[ @stack, $num ];
}
multi infix:<rpn> (@stack, $op where /^ '+' | '-' | '*' | '/' $/) {

my $lhs = @stack.pop;

my $rhs = @stack.pop;

my $res = do given $op {

when '+' { $rhs + $lhs }

when '-' { $rhs - $lhs }

when '*' { $rhs * $lhs }

when '/' { $rhs / $lhs }

}

[ @stack, $res ]
}
multi infix:<rpn> (@any, $unknown) {

die "Unkown expression near $unknown";
}
say [rpn] [], (~@*ARGS).words;


How to contribute?
#perl6 @ irc.freenode.org


Questions?
Daniel Ruoso
daniel@ruoso.com
http://daniel.ruoso.com/