SlideShare une entreprise Scribd logo
1  sur  136
Télécharger pour lire hors ligne
Introdução ao Perl 6
@that_garu
Perl 6
Perl, reescrito pela
própria comunidade.
Um novo Perl
mais moderno
mais amigável
mais poderoso
mais correto
mais seguro
Instalando
git clone https://github.com/tadzik/rakudobrew ~/.rakudobrew
export PATH=~/.rakudobrew/bin:$PATH
rakudobrew init
rakudobrew build moar
rakudobrew build-panda
panda install Linenoise
Números
6
say 6
say 6
6
say 6.WHAT
say 6.WHAT
(Int)
6.0
6.029e4
say 6.029e4.WHAT
say 6.WHAT
say 6.0.WHAT
(Int)
(Rat)
(Num)
say 7/2
say 7/2
3.5
Ruby
puts 7/2
Python 2
print 7/2
JavaScript
console.log(7/2)
C
#include <stdio.h>
int main (void) {
printf(“%f”, 7/2);
return 0;
}
Ruby
puts 7/2
3
Python 2
print 7/2
3
JavaScript
console.log(7/2)
3.5
C
WARNING: argument has type ‘int'
0.0000
#include <stdio.h>
int main (void) {
printf(“%f”, 7/2);
return 0;
}
Ruby
puts 7/2
3
Python 2
print 7/2
3
JavaScript
console.log(7/2)
3.5
C
#include <stdio.h>
int main (void) {
printf(“%d”, 7/2);
return 0;
}
3
say .1 + .2 - .3
say .1 + .2 - .3
0
Ruby
puts 0.1 + 0.2 - 0.3
Python 2
print .1 + .2 - .3
JavaScript
console.log(.1 + .2 - .3)
Perl 5
say .1 + .2 - .3
Ruby
puts 0.1 + 0.2 - 0.3
5.551115123125783e-17
Python 2
print .1 + .2 - .3
5.55111512313e-17
JavaScript
console.log(.1 + .2 - .3)
Perl 5
5.551115123125783e-17
say .1 + .2 - .3
5.55111512312578e-17
say 7.2.numerator
36
say 7.2.denominator
5
say 7.2.nude
(36 5)
say 36/5
7.2
Números
೬
say ೬.WHAT
(Int)
say ೬ + 1
7
Strings
say “Alô, YAPC"
say 'Alô, YAPC'
say 「Alô, YAPC」
say q|Alô, YAPC|
say ‘YA’ ~ ‘PC’
YAPC
say uc(‘yapc’)
YAPC
say ‘yapc’.uc
YAPC
say “c[DROMEDARY CAMEL]"
🐪
say ‘🐪’
🐪
say ‘🐪’.chars
1
‘YAPC::BR’.ends-with(‘BR')
True
Variáveis
my $var
say $var.WHAT
(Any)
my Int $var
say $var.WHAT
(Int)
my $resposta = 42
say $resposta.WHAT
(Int)
my @paises = (

‘Brasil’,

‘Chile’

);
my @paises =

‘Brasil’,

‘Chile’

;
my @paises = qw{Brasil Chile};
my @paises = <Brasil Chile>;
my @paises = <<

Brasil

Chile

“Reino Unido"

>>;
say @paises.elems
3
say @paises[0]
Brasil
say @paises[*-1]
Reino Unido
say @paises[^2]
(Brasil Chile)
say 0...10
(0 1 2 3 4 5 6 7 8 9 10)
say 0,2...10
(0 2 4 6 8 10)
say 2, 4, 8...100
(2 4 8 16 32 64)
my @lazy = 2, 4, 8...*;

say @lazy[20]
2097152
my @primes = grep { .is-prime }, 1..*;

say @primes[^10]
(2 3 5 7 11 13 17 19 23 29)
my @fib = 0, 1, * + * ... *;

say @fib[^10]
(0 1 1 2 3 5 8 13 21 34)
my %capitais = (

‘Brasil' => ‘Brasília',

‘Chile' => ‘Santiago’,

);
my %capitais =

‘Brasil' => ‘Brasília',

‘Chile' => ‘Santiago’,

;
say %capitais.elems
2
say %capitais{‘Brasil'}
Brasília
say %capitais<Brasil>
Brasília
say %capitais< Brasil Chile >
(Brasília Santiago)
%capitais<Brasil>:exists
True
Condicionais
if / elsif / else / unless

given - when
if ($x < 10) {

...

}
if $x < 10 {

...

}
if 5 < $x < 10 {

...

}
say $x unless 5 < $x < 10
Laços
foreach
while ($x < 10) {

...

}
while $x < 10 {

...

}
until $x < 10 {

...

}
while (1) {

...

}
loop {

...

}
loop (my $x = 0; $x < 10; $x++) {

...

}
for @capitais -> $cidade {

...

}
for ^10 -> $n1, $n2 {

...

}
I/O
my $nome = prompt “nome:"
my $dados = slurp ‘arquivo.txt'
spurt ‘arquivo.txt’, $dados
my @linhas = ‘arquivo.txt’.IO.lines
my $fh = open ‘arquivo.txt’;



for $fh.lines -> $line {

say $line if $line ~~ /abc/;

}
my $fh = open ‘arquivo.txt’;



for $fh.lines {

.say if /abc/;

}
my $fh = open ‘arquivo.txt’;



.say if /abc/ for $fh.lines;
funções
sub oi ($nome) {

return “oi, $nome!";

}
sub oi (Str $nome) {

return “oi, $nome!";

}
sub oi (Str $nome = 'Anônimo') {

return “oi, $nome!";

}
sub oi (Str $nome where *.chars > 0) {

return “oi, $nome!";

}
subset NonEmptyStr of Str where *.chars > 0;



sub oi (NonEmptyStr $nome) {

return “oi, $nome!";

}
subset NonEmptyStr of Str where *.chars > 0;



sub oi (NonEmptyStr $nome) is cached {

return “oi, $nome!";

}
subset NonEmptyStr of Str where *.chars > 0;



sub oi (NonEmptyStr $nome) returns Str {

return “oi, $nome!";

}
subset NonEmptyStr of Str where *.chars > 0;



sub oi (NonEmptyStr $nome) is cached returns Str {

return “oi, $nome!";

}
sub dobra (Int $num) {

return $num * 2;

}
multi dobra (Int $num) {

return $num * 2;

}
multi dobra (Int $num) {

return $num * 2;

}



multi dobra (Str $palavra) {

return $palavra x 2;

}
fizzbuzz

sem condicionais?
sub fizzbuzz($n) {

multi case($, $) { $n }

multi case(0, $) { “fizz" }

multi case($, 0) { “buzz" }

multi case(0, 0) { "fizzbuzz" }



case $n % 3, $n % 5;

}
classes
class Point {

has $.x = 0;

has $.y = 0;
method Str { “[$.x,$.y]” }

}







my $ponto = Point.new(x => 4,y => 7);

say $ponto.x; # 4

say $ponto.y; # 7

say “$ponto" # [4,7]
class Point {

has $.x = 0;

has $.y = 0;
method Str { “[$.x,$.y]” }

method set (:$x = $.x, :$y = $.y) {

$!x = $x; $!y = $y;

}

}

my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.set( y => -1 );

say “$ponto" # [4,-1]
class Point {

has Real $.x = 0;

has Real $.y = 0;
method Str { “[$.x,$.y]” }

method set (:$x = $.x, :$y = $.y) {

$!x = $x; $!y = $y;

}

}

my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.set( y => -1 );

say “$ponto" # [4,-1]
class Point {

has Real $.x is rw = 0;

has Real $.y is rw = 0;
method Str { “[$.x,$.y]” }

}







my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.y = -1;

say “$ponto" # [4,-1]
class Point {

subset Limitado of Real where -10 <= * <= 10;

has Limitado $.x is rw = 0;

has Limitado $.y is rw = 0;
method Str { “[$.x,$.y]” }

}





my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.y = -1;

say “$ponto" # [4,-1]
class Point {

subset Limitado of Real where -10 .. 10;

has Limitado $.x is rw = 0;

has Limitado $.y is rw = 0;
method Str { “[$.x,$.y]” }

}





my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.y = -1;

say “$ponto" # [4,-1]
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = 0;

has Limitado $.y is rw = 0;
method Str { “[$.x,$.y]” }

}





my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.y = -1;

say “$ponto" # [4,-1]
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';
method Str { “[$.x,$.y]” }

}





my $ponto = Point.new(x => 4,y => 7);

say “$ponto" # [4,7]

$ponto.y = -1;

say “$ponto" # [4,-1]
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}





my $ponto = Point.new(x => 4,y => 7);

$ponto.y = -1;

say $ponto.perl # Point.new(x => 4, y => -1)

class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
package Point {

use Carp;

use overload '""' => &Str, fallback => 1;


sub _pointlimit {
my ( $class, $num ) = @_;
unless ( $num >= -10 && $num <= 10 ) {
croak "...";

}

}

sub new {

my ( $class, $x, $y ) = @_;

my $self = bless { x => undef, y => undef } => $class;

$self->x($x);

$self->y($y);

return $self;
}

sub x {

my ( $self, $x ) = @_;

$self->_pointlimit ($x);

$self->{x} = $x;
}

sub y { 

my ( $self, $y ) = @_;

$self->_pointlimit ($y);

$self->{y} = $y;

}

sub Str {

my $self = shift;

return sprintf "[%f,%f]" => $self->x, $self->y;

}

}
Perl 5 (core)
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
package Point {
use Moose;
use overload '""' => &Str, fallback => 1;
use Moose::Util::TypeConstraints;
subtype "PointLimit" => as 'Num'
=> where { $_ >= -10 && $_ <= 10 }
=> message { "$_ must be a Num between -10 and 10, inclusive" };

has [qw/x y/] => (
is => 'rw',
isa => 'PointLimit',
required => 1,
);
sub Str {
my $self = shift;
return sprintf "[%f,%f]" => $self->x, $self->y;
}

}
Perl 5 (Moose)
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
#include <iostream>
#include <sstream>
class Point {
double x_, y_;
public:
Point (double x, double y) : x_(constrain(x)), y_(constrain(y)) {}
double x () const { return x_; }
double y () const { return y_; }
void x (double num) { x_ = constrain(num); }
void y (double num) { y_ = constrain(num); }
friend std::ostream & operator<< (std::ostream & stream, const Point & point) {
stream << '[' << point.x() << ',' << point.y() << ']';
return stream;
}

private: 

static double constrain (double num) {

if (num < -10 || num > 10) {

std::stringstream ss;

ss << "'" << num << "' is not a real number between -10 and 10, inclusive";

throw(ss.str());

}
return num;

}
};
C++
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
public class Point {
private static final double X_MIN = -10.0, X_MAX = 10.0;
private static final double Y_MIN = -10.0, Y_MAX = 10.0;
private double x, y;
public Point(double x, double y) throws IllegalArgumentException {
setX(x);
setY(y);

}
public double getX() { return x; }
public double getY() { return y; }
public void setX(double x) throws IllegalArgumentException {
if (x < X_MIN || x > X_MAX)
throw new IllegalArgumentException("...");
this.x = x;
}
public void setY(double y) throws IllegalArgumentException {
if (y < Y_MIN || y > Y_MIN)
throw new IllegalArgumentException("...");
this.y = y; }
@Override
public String toString() {
return String.format("[%.1f,%.1f]", x, y);
}
}
Java
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
class PointLimit:
def __init__(self, name):

self.name = name
def __get__(self, point, owner):
return point.__dict__.get(self.name)
def __set__(self, point, value):
if not -10 < value < 10:
raise ValueError('Value %d is out of range' % value)
point.__dict__[self.name] = value
class Point:
x = PointLimit('x');
y = PointLimit('y');

def __init__(self, x, y):
self.x = x
self.y = y
def __str__(self):
return "[%f,%f]" % (self.x, self.y)
Python 3
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
function definePointLimit(point, name) {
Object.defineProperty(point, name, {
set: function (value) {
if (value < -10 || value > 10)
throw 'Value ' + value + ' is out of range';
point['_' + name] = value;
},
get: function () {
return point['_' + name];
}
});

}
function Point(x, y) {
definePointLimit(this, 'x');
definePointLimit(this, 'y');

this.x = x; 

this.y = y;

}
Point.prototype.toString = function() {
return '[' + this.x + ',' + this.y + ']';
}
JavaScript
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
class Point
POINT_RANGE = -10..10

attr_constrained x: POINT_RANGE, y: POINT_RANGE

def initialize
@x = 0
@y = 0

end
def to_s
"[#{x},#{y}]"
end
private
def self.attr_constrained(attrs_and_constraints)
attrs_and_constraints.each do |attr, constraint|
attr_reader attr
define_method(:"#{attr}=") do |value|
raise "#{value} is not a valid value for #{attr}" 
unless constraint === value
instance_variable_set :"@#{attr}", value
end
end

end 

end
Ruby
class Point {

subset Limitado where -10.0 .. 10.0;

has Limitado $.x is rw = die ‘x is required';

has Limitado $.y is rw = die ‘y is required';

}
Perl 6
package point
import "fmt"

import "errors"
type Point struct {

x, y float64 

}
func NewPoint(x, y float64) (*Point, error) {

p := &Point{x, y}

if !IsValid(x) {

return nil, errors.New("Point x out of range!”)

}

if !IsValid(y) {

return nil, errors.New("Point y out of range!”)

}

return p, nil

}
func IsValid(p float64) (result bool) {

if p >= -10 && p <= 10 { 

result = true

} 

return

}
func (p *Point) String() string {

return fmt.Sprintf("[%v,%v]", p.x, p.y) 

}

func (p *Point) SetX(x float64) (float64, error) { 

ox := p.x

if !IsValid(x) {

return ox, errors.New("Point out of range!")

} 

return ox, nil

}
func (p *Point) SetY(y float64) (float64, error) { oy := p.y 

if !IsValid(y) {

return oy, errors.New("Point out of range!")

} 

return oy, nil

} 

func (p *Point) GetX() float64 {

return p.x 

}

func (p *Point) GetY() float64 { 

return p.y

}
Go
CLI
async
gramáticas
exceções MOP
Native Calling
junctions
docs.perl6.org
Obrigado!
Dúvidas?
@that_garu
Créditos e informações adicionais
Carl Mäsak - fizzbuzz.p6:

https://gist.github.com/masak/b9371625ad85cfe0faba
Jonathan Worthington - Perl 6 hands-on tutorial
http://jnthn.net/papers/2015-spw-perl6-course.pdf
Curtis “Ovid" Poe - Perl 6 for mere mortals
http://www.slideshare.net/Ovid/perl-6-for-mere-mortals

Contenu connexe

Tendances

OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersLin Yo-An
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smartlichtkind
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)Nikita Popov
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128PrinceGuru MS
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)brian d foy
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Seri Moth
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6 brian d foy
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Lin Yo-An
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?Nikita Popov
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2osfameron
 
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
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic trapsDamien Seguy
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎juzihua1102
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎anzhong70
 

Tendances (20)

PHP and MySQL
PHP and MySQLPHP and MySQL
PHP and MySQL
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
OSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP hatersOSDC.TW - Gutscript for PHP haters
OSDC.TW - Gutscript for PHP haters
 
Wx::Perl::Smart
Wx::Perl::SmartWx::Perl::Smart
Wx::Perl::Smart
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)PHP 7 – What changed internally? (Forum PHP 2015)
PHP 7 – What changed internally? (Forum PHP 2015)
 
Php tips-and-tricks4128
Php tips-and-tricks4128Php tips-and-tricks4128
Php tips-and-tricks4128
 
Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)Learning Perl 6 (NPW 2007)
Learning Perl 6 (NPW 2007)
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02Jsphp 110312161301-phpapp02
Jsphp 110312161301-phpapp02
 
Learning Perl 6
Learning Perl 6 Learning Perl 6
Learning Perl 6
 
Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015Code Generation in PHP - PHPConf 2015
Code Generation in PHP - PHPConf 2015
 
PHP 7 – What changed internally?
PHP 7 – What changed internally?PHP 7 – What changed internally?
PHP 7 – What changed internally?
 
Functional Pe(a)rls version 2
Functional Pe(a)rls version 2Functional Pe(a)rls version 2
Functional Pe(a)rls version 2
 
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)
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Top 10 php classic traps
Top 10 php classic trapsTop 10 php classic traps
Top 10 php classic traps
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 

Similaire à Introdução ao Perl 6

Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Masahiro Nagano
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackVic Metcalfe
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python DevelopersCarlos Vences
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHPIan Barber
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなしMasahiro Honma
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of RubyTom Crinson
 
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 / XSolveXSolve
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 

Similaire à Introdução ao Perl 6 (20)

Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
Designing Opeation Oriented Web Applications / YAPC::Asia Tokyo 2011
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
An Elephant of a Different Colour: Hack
An Elephant of a Different Colour: HackAn Elephant of a Different Colour: Hack
An Elephant of a Different Colour: Hack
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Presentation1
Presentation1Presentation1
Presentation1
 
Php functions
Php functionsPhp functions
Php functions
 
Introduction to Groovy
Introduction to GroovyIntroduction to Groovy
Introduction to Groovy
 
Bag of tricks
Bag of tricksBag of tricks
Bag of tricks
 
PHP for Python Developers
PHP for Python DevelopersPHP for Python Developers
PHP for Python Developers
 
Smelling your code
Smelling your codeSmelling your code
Smelling your code
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
 
Document Classification In PHP
Document Classification In PHPDocument Classification In PHP
Document Classification In PHP
 
循環参照のはなし
循環参照のはなし循環参照のはなし
循環参照のはなし
 
Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
PHP Tips & Tricks
PHP Tips & TricksPHP Tips & Tricks
PHP Tips & Tricks
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
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
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

Plus de garux

Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)garux
 
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensa
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensaSeja um Perl Core Hacker - é (muito) mais fácil do que você pensa
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensagarux
 
Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perlgarux
 
Perl Moderno, dia5
Perl Moderno, dia5Perl Moderno, dia5
Perl Moderno, dia5garux
 
Perl Moderno, dia4
Perl Moderno, dia4Perl Moderno, dia4
Perl Moderno, dia4garux
 
Perl Moderno, dia3
Perl Moderno, dia3Perl Moderno, dia3
Perl Moderno, dia3garux
 
Perl Moderno, dia2
Perl Moderno, dia2Perl Moderno, dia2
Perl Moderno, dia2garux
 
Perl Moderno, dia1
Perl Moderno, dia1Perl Moderno, dia1
Perl Moderno, dia1garux
 
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao MooseOrientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moosegarux
 
Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)garux
 
Jogos em Perl
Jogos em PerlJogos em Perl
Jogos em Perlgarux
 
Logging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perlLogging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perlgarux
 
Novidades no Perl 5.10
Novidades no Perl 5.10Novidades no Perl 5.10
Novidades no Perl 5.10garux
 
Desenvolvimento Rápido de Programas Linha de Comando
Desenvolvimento Rápido de Programas Linha de ComandoDesenvolvimento Rápido de Programas Linha de Comando
Desenvolvimento Rápido de Programas Linha de Comandogarux
 

Plus de garux (14)

Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)Communities - Perl edition (RioJS)
Communities - Perl edition (RioJS)
 
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensa
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensaSeja um Perl Core Hacker - é (muito) mais fácil do que você pensa
Seja um Perl Core Hacker - é (muito) mais fácil do que você pensa
 
Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perl
 
Perl Moderno, dia5
Perl Moderno, dia5Perl Moderno, dia5
Perl Moderno, dia5
 
Perl Moderno, dia4
Perl Moderno, dia4Perl Moderno, dia4
Perl Moderno, dia4
 
Perl Moderno, dia3
Perl Moderno, dia3Perl Moderno, dia3
Perl Moderno, dia3
 
Perl Moderno, dia2
Perl Moderno, dia2Perl Moderno, dia2
Perl Moderno, dia2
 
Perl Moderno, dia1
Perl Moderno, dia1Perl Moderno, dia1
Perl Moderno, dia1
 
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao MooseOrientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
Orientação a Objetos Elegante e Eficiente: Brevíssima Introdução ao Moose
 
Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)Perl Quiz 2009 (YAPC::BR)
Perl Quiz 2009 (YAPC::BR)
 
Jogos em Perl
Jogos em PerlJogos em Perl
Jogos em Perl
 
Logging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perlLogging e depuração enterprise-level com Log4perl
Logging e depuração enterprise-level com Log4perl
 
Novidades no Perl 5.10
Novidades no Perl 5.10Novidades no Perl 5.10
Novidades no Perl 5.10
 
Desenvolvimento Rápido de Programas Linha de Comando
Desenvolvimento Rápido de Programas Linha de ComandoDesenvolvimento Rápido de Programas Linha de Comando
Desenvolvimento Rápido de Programas Linha de Comando
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Dernier (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

Introdução ao Perl 6

  • 1. Introdução ao Perl 6 @that_garu
  • 11. git clone https://github.com/tadzik/rakudobrew ~/.rakudobrew export PATH=~/.rakudobrew/bin:$PATH rakudobrew init rakudobrew build moar rakudobrew build-panda panda install Linenoise
  • 13. 6
  • 14. say 6
  • 18. 6.0
  • 20. say 6.029e4.WHAT say 6.WHAT say 6.0.WHAT (Int) (Rat) (Num)
  • 23. Ruby puts 7/2 Python 2 print 7/2 JavaScript console.log(7/2) C #include <stdio.h> int main (void) { printf(“%f”, 7/2); return 0; }
  • 24. Ruby puts 7/2 3 Python 2 print 7/2 3 JavaScript console.log(7/2) 3.5 C WARNING: argument has type ‘int' 0.0000 #include <stdio.h> int main (void) { printf(“%f”, 7/2); return 0; }
  • 25. Ruby puts 7/2 3 Python 2 print 7/2 3 JavaScript console.log(7/2) 3.5 C #include <stdio.h> int main (void) { printf(“%d”, 7/2); return 0; } 3
  • 26. say .1 + .2 - .3
  • 27. say .1 + .2 - .3 0
  • 28. Ruby puts 0.1 + 0.2 - 0.3 Python 2 print .1 + .2 - .3 JavaScript console.log(.1 + .2 - .3) Perl 5 say .1 + .2 - .3
  • 29. Ruby puts 0.1 + 0.2 - 0.3 5.551115123125783e-17 Python 2 print .1 + .2 - .3 5.55111512313e-17 JavaScript console.log(.1 + .2 - .3) Perl 5 5.551115123125783e-17 say .1 + .2 - .3 5.55111512312578e-17
  • 30. say 7.2.numerator 36 say 7.2.denominator 5 say 7.2.nude (36 5) say 36/5 7.2
  • 32.
  • 34. say ೬ + 1 7
  • 35.
  • 41. say ‘YA’ ~ ‘PC’ YAPC
  • 55. my @paises = (
 ‘Brasil’,
 ‘Chile’
 );
  • 57. my @paises = qw{Brasil Chile};
  • 58. my @paises = <Brasil Chile>;
  • 59. my @paises = <<
 Brasil
 Chile
 “Reino Unido"
 >>;
  • 64. say 0...10 (0 1 2 3 4 5 6 7 8 9 10)
  • 65. say 0,2...10 (0 2 4 6 8 10)
  • 66. say 2, 4, 8...100 (2 4 8 16 32 64)
  • 67. my @lazy = 2, 4, 8...*;
 say @lazy[20] 2097152
  • 68. my @primes = grep { .is-prime }, 1..*;
 say @primes[^10] (2 3 5 7 11 13 17 19 23 29)
  • 69. my @fib = 0, 1, * + * ... *;
 say @fib[^10] (0 1 1 2 3 5 8 13 21 34)
  • 70. my %capitais = (
 ‘Brasil' => ‘Brasília',
 ‘Chile' => ‘Santiago’,
 );
  • 71. my %capitais =
 ‘Brasil' => ‘Brasília',
 ‘Chile' => ‘Santiago’,
 ;
  • 75. say %capitais< Brasil Chile > (Brasília Santiago)
  • 78. if / elsif / else / unless
 given - when
  • 79. if ($x < 10) {
 ...
 }
  • 80. if $x < 10 {
 ...
 }
  • 81. if 5 < $x < 10 {
 ...
 }
  • 82. say $x unless 5 < $x < 10
  • 85. while ($x < 10) {
 ...
 }
  • 86. while $x < 10 {
 ...
 }
  • 87. until $x < 10 {
 ...
 }
  • 90. loop (my $x = 0; $x < 10; $x++) {
 ...
 }
  • 91. for @capitais -> $cidade {
 ...
 }
  • 92. for ^10 -> $n1, $n2 {
 ...
 }
  • 93. I/O
  • 94. my $nome = prompt “nome:"
  • 95. my $dados = slurp ‘arquivo.txt'
  • 97. my @linhas = ‘arquivo.txt’.IO.lines
  • 98. my $fh = open ‘arquivo.txt’;
 
 for $fh.lines -> $line {
 say $line if $line ~~ /abc/;
 }
  • 99. my $fh = open ‘arquivo.txt’;
 
 for $fh.lines {
 .say if /abc/;
 }
  • 100. my $fh = open ‘arquivo.txt’;
 
 .say if /abc/ for $fh.lines;
  • 102. sub oi ($nome) {
 return “oi, $nome!";
 }
  • 103. sub oi (Str $nome) {
 return “oi, $nome!";
 }
  • 104. sub oi (Str $nome = 'Anônimo') {
 return “oi, $nome!";
 }
  • 105. sub oi (Str $nome where *.chars > 0) {
 return “oi, $nome!";
 }
  • 106. subset NonEmptyStr of Str where *.chars > 0;
 
 sub oi (NonEmptyStr $nome) {
 return “oi, $nome!";
 }
  • 107. subset NonEmptyStr of Str where *.chars > 0;
 
 sub oi (NonEmptyStr $nome) is cached {
 return “oi, $nome!";
 }
  • 108. subset NonEmptyStr of Str where *.chars > 0;
 
 sub oi (NonEmptyStr $nome) returns Str {
 return “oi, $nome!";
 }
  • 109. subset NonEmptyStr of Str where *.chars > 0;
 
 sub oi (NonEmptyStr $nome) is cached returns Str {
 return “oi, $nome!";
 }
  • 110. sub dobra (Int $num) {
 return $num * 2;
 }
  • 111. multi dobra (Int $num) {
 return $num * 2;
 }
  • 112. multi dobra (Int $num) {
 return $num * 2;
 }
 
 multi dobra (Str $palavra) {
 return $palavra x 2;
 }
  • 114. sub fizzbuzz($n) {
 multi case($, $) { $n }
 multi case(0, $) { “fizz" }
 multi case($, 0) { “buzz" }
 multi case(0, 0) { "fizzbuzz" }
 
 case $n % 3, $n % 5;
 }
  • 116. class Point {
 has $.x = 0;
 has $.y = 0; method Str { “[$.x,$.y]” }
 }
 
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say $ponto.x; # 4
 say $ponto.y; # 7
 say “$ponto" # [4,7]
  • 117. class Point {
 has $.x = 0;
 has $.y = 0; method Str { “[$.x,$.y]” }
 method set (:$x = $.x, :$y = $.y) {
 $!x = $x; $!y = $y;
 }
 }
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.set( y => -1 );
 say “$ponto" # [4,-1]
  • 118. class Point {
 has Real $.x = 0;
 has Real $.y = 0; method Str { “[$.x,$.y]” }
 method set (:$x = $.x, :$y = $.y) {
 $!x = $x; $!y = $y;
 }
 }
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.set( y => -1 );
 say “$ponto" # [4,-1]
  • 119. class Point {
 has Real $.x is rw = 0;
 has Real $.y is rw = 0; method Str { “[$.x,$.y]” }
 }
 
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.y = -1;
 say “$ponto" # [4,-1]
  • 120. class Point {
 subset Limitado of Real where -10 <= * <= 10;
 has Limitado $.x is rw = 0;
 has Limitado $.y is rw = 0; method Str { “[$.x,$.y]” }
 }
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.y = -1;
 say “$ponto" # [4,-1]
  • 121. class Point {
 subset Limitado of Real where -10 .. 10;
 has Limitado $.x is rw = 0;
 has Limitado $.y is rw = 0; method Str { “[$.x,$.y]” }
 }
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.y = -1;
 say “$ponto" # [4,-1]
  • 122. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = 0;
 has Limitado $.y is rw = 0; method Str { “[$.x,$.y]” }
 }
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.y = -1;
 say “$ponto" # [4,-1]
  • 123. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required'; method Str { “[$.x,$.y]” }
 }
 
 
 my $ponto = Point.new(x => 4,y => 7);
 say “$ponto" # [4,7]
 $ponto.y = -1;
 say “$ponto" # [4,-1]
  • 124. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 }
 
 
 my $ponto = Point.new(x => 4,y => 7);
 $ponto.y = -1;
 say $ponto.perl # Point.new(x => 4, y => -1)

  • 125. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 package Point {
 use Carp;
 use overload '""' => &Str, fallback => 1; 
 sub _pointlimit { my ( $class, $num ) = @_; unless ( $num >= -10 && $num <= 10 ) { croak "...";
 }
 }
 sub new {
 my ( $class, $x, $y ) = @_;
 my $self = bless { x => undef, y => undef } => $class;
 $self->x($x);
 $self->y($y);
 return $self; }
 sub x {
 my ( $self, $x ) = @_;
 $self->_pointlimit ($x);
 $self->{x} = $x; }
 sub y { 
 my ( $self, $y ) = @_;
 $self->_pointlimit ($y);
 $self->{y} = $y;
 }
 sub Str {
 my $self = shift;
 return sprintf "[%f,%f]" => $self->x, $self->y;
 }
 } Perl 5 (core)
  • 126. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 package Point { use Moose; use overload '""' => &Str, fallback => 1; use Moose::Util::TypeConstraints; subtype "PointLimit" => as 'Num' => where { $_ >= -10 && $_ <= 10 } => message { "$_ must be a Num between -10 and 10, inclusive" };
 has [qw/x y/] => ( is => 'rw', isa => 'PointLimit', required => 1, ); sub Str { my $self = shift; return sprintf "[%f,%f]" => $self->x, $self->y; }
 } Perl 5 (Moose)
  • 127. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 #include <iostream> #include <sstream> class Point { double x_, y_; public: Point (double x, double y) : x_(constrain(x)), y_(constrain(y)) {} double x () const { return x_; } double y () const { return y_; } void x (double num) { x_ = constrain(num); } void y (double num) { y_ = constrain(num); } friend std::ostream & operator<< (std::ostream & stream, const Point & point) { stream << '[' << point.x() << ',' << point.y() << ']'; return stream; }
 private: 
 static double constrain (double num) {
 if (num < -10 || num > 10) {
 std::stringstream ss;
 ss << "'" << num << "' is not a real number between -10 and 10, inclusive";
 throw(ss.str());
 } return num;
 } }; C++
  • 128. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 public class Point { private static final double X_MIN = -10.0, X_MAX = 10.0; private static final double Y_MIN = -10.0, Y_MAX = 10.0; private double x, y; public Point(double x, double y) throws IllegalArgumentException { setX(x); setY(y);
 } public double getX() { return x; } public double getY() { return y; } public void setX(double x) throws IllegalArgumentException { if (x < X_MIN || x > X_MAX) throw new IllegalArgumentException("..."); this.x = x; } public void setY(double y) throws IllegalArgumentException { if (y < Y_MIN || y > Y_MIN) throw new IllegalArgumentException("..."); this.y = y; } @Override public String toString() { return String.format("[%.1f,%.1f]", x, y); } } Java
  • 129. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 class PointLimit: def __init__(self, name):
 self.name = name def __get__(self, point, owner): return point.__dict__.get(self.name) def __set__(self, point, value): if not -10 < value < 10: raise ValueError('Value %d is out of range' % value) point.__dict__[self.name] = value class Point: x = PointLimit('x'); y = PointLimit('y');
 def __init__(self, x, y): self.x = x self.y = y def __str__(self): return "[%f,%f]" % (self.x, self.y) Python 3
  • 130. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 function definePointLimit(point, name) { Object.defineProperty(point, name, { set: function (value) { if (value < -10 || value > 10) throw 'Value ' + value + ' is out of range'; point['_' + name] = value; }, get: function () { return point['_' + name]; } });
 } function Point(x, y) { definePointLimit(this, 'x'); definePointLimit(this, 'y');
 this.x = x; 
 this.y = y;
 } Point.prototype.toString = function() { return '[' + this.x + ',' + this.y + ']'; } JavaScript
  • 131. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 class Point POINT_RANGE = -10..10
 attr_constrained x: POINT_RANGE, y: POINT_RANGE
 def initialize @x = 0 @y = 0
 end def to_s "[#{x},#{y}]" end private def self.attr_constrained(attrs_and_constraints) attrs_and_constraints.each do |attr, constraint| attr_reader attr define_method(:"#{attr}=") do |value| raise "#{value} is not a valid value for #{attr}" unless constraint === value instance_variable_set :"@#{attr}", value end end
 end 
 end Ruby
  • 132. class Point {
 subset Limitado where -10.0 .. 10.0;
 has Limitado $.x is rw = die ‘x is required';
 has Limitado $.y is rw = die ‘y is required';
 } Perl 6 package point import "fmt"
 import "errors" type Point struct {
 x, y float64 
 } func NewPoint(x, y float64) (*Point, error) {
 p := &Point{x, y}
 if !IsValid(x) {
 return nil, errors.New("Point x out of range!”)
 }
 if !IsValid(y) {
 return nil, errors.New("Point y out of range!”)
 }
 return p, nil
 } func IsValid(p float64) (result bool) {
 if p >= -10 && p <= 10 { 
 result = true
 } 
 return
 } func (p *Point) String() string {
 return fmt.Sprintf("[%v,%v]", p.x, p.y) 
 }
 func (p *Point) SetX(x float64) (float64, error) { 
 ox := p.x
 if !IsValid(x) {
 return ox, errors.New("Point out of range!")
 } 
 return ox, nil
 } func (p *Point) SetY(y float64) (float64, error) { oy := p.y 
 if !IsValid(y) {
 return oy, errors.New("Point out of range!")
 } 
 return oy, nil
 } 
 func (p *Point) GetX() float64 {
 return p.x 
 }
 func (p *Point) GetY() float64 { 
 return p.y
 } Go
  • 136. Créditos e informações adicionais Carl Mäsak - fizzbuzz.p6:
 https://gist.github.com/masak/b9371625ad85cfe0faba Jonathan Worthington - Perl 6 hands-on tutorial http://jnthn.net/papers/2015-spw-perl6-course.pdf Curtis “Ovid" Poe - Perl 6 for mere mortals http://www.slideshare.net/Ovid/perl-6-for-mere-mortals