SlideShare ist ein Scribd-Unternehmen logo
1 von 66
Downloaden Sie, um offline zu lesen
Rakudo Perl 6
What you can do today




Jonathan Worthington
РИТ++ 2010
Rakudo Perl 6: What You Can Do Today




        Intro…
       XXX TODO
Rakudo Perl 6: What You Can Do Today




              Perl 6
Rakudo Perl 6: What You Can Do Today
What is Perl 6?
   Take the things that make Perl great…
     Practical - focus on getting the job done
     Multi-paradigm – because there isn't one
     approach that's good for all problems
     Linguistic influences – because it's a
     programming language
     Making the easy things easy and the hard
     things possible
Rakudo Perl 6: What You Can Do Today
What is Perl 6?
   Build a new Perlish language that is…
     More regular – less special cases
     More readable and more maintainable
     More expressive
     More OO, more functional, more
     declarative, more parallel…
     Easy things even easier
     Harder things even more in reach
Rakudo Perl 6: What You Can Do Today
1 Specification, Many Implementations
   Unlike Perl 5, Perl 6 has a written language
   specification
     No "official" implementation
   Like Perl 5, Perl 6 has a language test suite
     A conforming implementation should pass
     the test suite
     A kind of "executable specification"
     Currently around 40,000 tests
Rakudo Perl 6: What You Can Do Today




            Rakudo
Rakudo Perl 6: What You Can Do Today
What is Rakudo?
   The most actively developed Perl 6 compiler
   Implements a large portion of the Perl 6
   specification (though still some way to go)
   Today passing over 30,000 tests from the
   Perl 6 specification test suite (though the
   suite is still growing ☺)
   Currently targets the Parrot Virtual Machine
   Later in the year, we plan to target at least
   one other platform too
Rakudo Perl 6: What You Can Do Today
How Rakudo Works
   Written in…
     NQP (Bootstrapped subset of Perl 6)
     Compiler core (grammar and AST construction),
     some of the meta-model, module location/loading)

     Perl 6
     The majority of the built-ins and operators

     Parrot Intermediate Language
     Some lower-level builtins and "glue"

     C
     Dispatchers, signature binder, other VM
     customizations and glue
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: Parsing
   First, Rakudo parses your program
   Parser is written in Perl 6 Regexes
 token statement_control:sym<if> {
     <sym> :s
     <xblock>
     [ 'elsif's <xblock> ]*
     [ 'else's <else=.pblock> ]?
 }
   Some scary stuff…
     Might discover new operators during parse
     Have to run BEGIN blocks immediately
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   Whenever we finish parsing something (for
   example, an if statement), we run an "action
   method"
   This builds an Abstract Syntax Tree
     A representation of the program that is
     abstracted away from the language syntax
   Most action methods build up a more
   complex AST using smaller bits made by
   things we already parsed
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }




 PAST::Var.new(
   :name('$x'),
   :scope('lexical')
 )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }




 PAST::Var.new(        PAST::Val.new(
   :name('$x'),          :value(42)
   :scope('lexical')   )
 )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }


           PAST::Op.new(
             :pasttype('call'),
             :name('&infix:<==>'),
             …
           )

 PAST::Var.new(        PAST::Val.new(
   :name('$x'),          :value(42)
   :scope('lexical')   )
 )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }


           PAST::Op.new(
             :pasttype('call'),
             :name('&infix:<==>'),
             …
           )

 PAST::Var.new(        PAST::Val.new(
   :name('$x'),          :value(42)
   :scope('lexical')   )
 )                                      PAST::Val.new(
                                          :value('The Answer!')
                                        )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }


           PAST::Op.new(
             :pasttype('call'),
             :name('&infix:<==>'),
             …                          PAST::Op.new(
           )                              :pasttype('call'),
                                          :name('&say'),
                                          …
 PAST::Var.new(        PAST::Val.new(   )
   :name('$x'),          :value(42)
   :scope('lexical')   )
 )                                      PAST::Val.new(
                                          :value('The Answer!')
                                        )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }


           PAST::Op.new(                PAST::Block.new( … )
             :pasttype('call'),
             :name('&infix:<==>'),
             …                          PAST::Op.new(
           )                              :pasttype('call'),
                                          :name('&say'),
                                          …
 PAST::Var.new(        PAST::Val.new(   )
   :name('$x'),          :value(42)
   :scope('lexical')   )
 )                                      PAST::Val.new(
                                          :value('The Answer!')
                                        )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }
                       PAST::Op.new( :pasttype('if'), … )

           PAST::Op.new(                          PAST::Block.new( … )
             :pasttype('call'),
             :name('&infix:<==>'),
             …                                    PAST::Op.new(
           )                                        :pasttype('call'),
                                                    :name('&say'),
                                                    …
 PAST::Var.new(            PAST::Val.new(         )
   :name('$x'),              :value(42)
   :scope('lexical')       )
 )                                                PAST::Val.new(
                                                    :value('The Answer!')
                                                  )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: AST Construction
   if $x == 42 { say "The answer!"; }
                       PAST::Op.new( :pasttype('if'), … )

           PAST::Op.new(                          PAST::Block.new( … )
             :pasttype('call'),
             :name('&infix:<==>'),
             …                                    PAST::Op.new(
           )                                        :pasttype('call'),
                                                    :name('&say'),
                                                    …
 PAST::Var.new(            PAST::Val.new(         )
   :name('$x'),              :value(42)
   :scope('lexical')       )
 )                                                PAST::Val.new(
                                                    :value('The Answer!')
                                                  )
Rakudo Perl 6: What You Can Do Today
How Rakudo Works: Code Generation
   We take the AST and produce intermediate
   code for the target platform
   Today, we can only produce code in this
   stage for the Parrot VM
   Architecture means that we'll be able to add
   more backends in the future
   Can also insert optimization and program
   analysis phases at any point in the
   compilation pipeline
Rakudo Perl 6: What You Can Do Today



   Examples:
  What You Can
   Do Today In
     Rakudo
Rakudo Perl 6: What You Can Do Today
Examples
   We'll look at a range of small, everyday
   programming problems and for each one
   show…
     The Perl 6 code that solves it
     The output that code gives when run
   Hopefully, a good way for you to start to
   grasp some of the new syntax and features
   Show of some cool Perl 6 features ☺
   All examples shown today work in Rakudo
Rakudo Perl 6: What You Can Do Today

Problem
Say "Hello, world"
Solution
 say "Hello, world!"

Output
Hello, world!
Rakudo Perl 6: What You Can Do Today

Problem
Read input from the console
Solution
 print "Enter your name: ";
 my $name = $*IN.get;
 say "Hi $name!";

Output
Enter your name: Jonathan
Hi Jonathan!
Rakudo Perl 6: What You Can Do Today

Problem
Check a value is in a given range
Solution 1
 loop {
     print "Enter a number from 1 to 10: ";
     my $num = $*IN.get;
     unless 1 <= $num <= 10 { say "Fail!" }
 }

Output
Enter a number between 1 and 10: 3
Enter a number between 1 and 10: 42
Fail!
Rakudo Perl 6: What You Can Do Today

Problem
Check a value is in a given range
Solution 2
 loop {
     print "Enter a number from 1 to 10: ";
     my $num = $*IN.get;
     unless $num ~~ 1..10 { say "Fail!" }
 }

Output
Enter a number between 1 and 10: 3
Enter a number between 1 and 10: 42
Fail!
Rakudo Perl 6: What You Can Do Today

Problem
Add up a list of numbers
Solution
 my @nums = 1, 5, 7, -2, 3, 9, 11, -6, 14;
 say [+] @nums;

Output
42
Rakudo Perl 6: What You Can Do Today

Problem
Check if a list is sorted
Solution
 my   @a =   1,   1, 2,   3, 5, 8;
 my   @b =   9,   4, 1,   16, 36, 25;
 if   [<=]   @a   { say   '@a is sorted' }
 if   [<=]   @b   { say   '@b is sorted' }

Output
@a is sorted
Rakudo Perl 6: What You Can Do Today

Problem
Iterate over a list
Solution
 my @cities = <Lisbon Tokyo Seoul Riga>;
 for @cities -> $city {
     say "I've been to $city";
 }

Output
I've   been   to   Lisbon
I've   been   to   Tokyo
I've   been   to   Seoul
I've   been   to   Riga
Rakudo Perl 6: What You Can Do Today

Problem
Iterate over the keys and values of a hash
Solution
 my %distances =
     Bratislava =>   1084,
     Stockholm =>    442;
 for %distances.kv   -> $city, $distance {
     say "$city is   $distance km away";
 }

Output
Bratislava is 1084 km away
Stockholm is 442 km away
Rakudo Perl 6: What You Can Do Today

Problem
Check if any of a list of test scores is a pass
Solution
 my   @a = 75, 47, 90, 22, 80;
 my   @b = 61, 77, 94, 82, 60;
 my   @c = 45, 59, 33, 11, 19;
 if   any(@a) >= 60 { say "Some passes in A" }
 if   any(@b) >= 60 { say "Some passes in B" }
 if   any(@c) >= 60 { say "Some passes in C" }

Output
Some passes in A
Some passes in B
Rakudo Perl 6: What You Can Do Today

Problem
Check if all of a list of test scores are passes
Solution
 my   @a = 75, 47, 90, 22, 80;
 my   @b = 61, 77, 94, 82, 60;
 my   @c = 45, 59, 33, 11, 19;
 if   all(@a) >= 60 { say "All passes in A" }
 if   all(@b) >= 60 { say "All passes in B" }
 if   all(@c) >= 60 { say "All passes in C" }

Output
All passes in B
Rakudo Perl 6: What You Can Do Today

Problem
Check if none of a list of test scores is a pass
Solution
 my   @a = 75,   47, 90,   22,   80;
 my   @b = 61,   77, 94,   82,   60;
 my   @c = 45,   59, 33,   11,   19;
 if   none(@a)   >= 60 {   say   "No passes in A" }
 if   none(@b)   >= 60 {   say   "No passes in B" }
 if   none(@c)   >= 60 {   say   "No passes in C" }

Output
No passes in C
Rakudo Perl 6: What You Can Do Today

Problem
Get a random item from a list
Solution
 my @drinks = <wine beer vodka>;
 say "Tonight I'll drink { @drinks.pick }";

Output (results should vary ;-))
Tonight I'll drink vodka
Rakudo Perl 6: What You Can Do Today

Problem
Shuffle a list into a random order
Solution
 my @competitors = <Tina Lena Owen Peter>;
 my @order = @competitors.pick(*);
 for @order { .say }

Output (results should vary ;-))
Peter
Lena
Owen
Tina
Rakudo Perl 6: What You Can Do Today

Problem
Write and call a subroutine with parameters
Solution
 sub greet($greeting, $name) {
     say "$greeting, $name!";
 }
 greet("hello", "masak");

Output
hello, masak
Rakudo Perl 6: What You Can Do Today

Problem
Write a subroutine that only takes a number
Solution
 sub double(Num $n) { 2 * $n }
 say double(21);
 say double("oh no I'm not a number");

Output
42
Parameter type check failed; expected Num,
but got Str for $n in call to double
Rakudo Perl 6: What You Can Do Today

Problem
Use multi-subs to react differently by type
Solution
 multi double(Num $n) { 2 * $n }
 multi double(Str $s) { $s x 2 }
 say double(21);
 say double("boo");

Output
42
booboo
Rakudo Perl 6: What You Can Do Today

Problem
Compute factorial (recursively)
Solution
 multi fact($n) { $n * fact($n - 1) }
 multi fact(0) { 1 }
 say fact(1);
 say fact(10);

Output
1
3628800
Rakudo Perl 6: What You Can Do Today

Problem
Compute factorial (using a meta-operator)
Solution
 sub fact($n) { [*] 1..$n }
 say fact(1);
 say fact(10);

Output
1
3628800
Rakudo Perl 6: What You Can Do Today

Problem
Add a new factorial operator (so 10! works)
Solution
 sub postfix:<!>($n) { [*] 1..$n }
 say 1!;
 say 10!;

Output
1
3628800
Rakudo Perl 6: What You Can Do Today

Problem
Declare a class with attributes and a method
Solution
 class Product {
     has $.name; # Attr + accessor
     has $!price; # Attr only
     has $.discount is rw;
                  # Attr + lvalue accessor
     method get_price {
         return $!price - $!discount;
     }
 }
Rakudo Perl 6: What You Can Do Today

Problem
Instantiate a class and call a method on it
Solution
 my $prod = Product.new(
     name      => "Beer",
     price     => 500,
     discount => 60
 );
 say $prod.get_price;

Output
440
Rakudo Perl 6: What You Can Do Today

Problem
Get/set attributes through accessors
Solution
 say $prod.name;
 $prod.discount = 40;
 say $prod.get_price;
 $prod.name = 'Wine';

Output
Beer
460
Cannot assign to readonly variable.
Rakudo Perl 6: What You Can Do Today

Problem
Call a method on every object in a list
Solution
 my @products =
   Product.new(name => 'Beer', price => 500),
   Product.new(name => 'Wine', price => 450),
   Product.new(name => 'Vodka', price => 1600);
 my @uc_names = @products>>.name>>.uc;
 for @uc_names { .say }

Output
BEER
WINE
VODKA
Rakudo Perl 6: What You Can Do Today

Problem
Introspect a class to find its methods
Solution
 my @meths = Product.^methods(:local);
 for @meths>>.name { .say }

Output
get_price
discount
name
Rakudo Perl 6: What You Can Do Today

Problem
Sort an array of objects by result of a method
Solution (Example 1)
 my @products =
   Product.new(name => 'Beer', price => 500),
   Product.new(name => 'Wine', price => 450),
   Product.new(name => 'Vodka', price => 1600);
 my @sorted = @products.sort(*.name);
 for @sorted { .name.say }

Output (Example 1)
Beer
Vodka
Wine
Rakudo Perl 6: What You Can Do Today

Problem
Sort an array of objects by result of a method
Solution (Example 2)
 my @products =
   Product.new(name => 'Beer', price => 500),
   Product.new(name => 'Wine', price => 450),
   Product.new(name => 'Vodka', price => 1600);
 my @sorted = @products.sort(*.get_price);
 for @sorted { .name.say }

Output (Example 2)
Wine
Beer
Vodka
Rakudo Perl 6: What You Can Do Today

Problem
Find minimum and maximum values from a list
Solution (Example 1)
 my @temperatures = -3, 5, 7, 2, -1, -4, 0;
 say "Minimum was " ~ @temperatures.min;
 say "Maximum was " ~ @temperatures.max;

Output (Example 1)
Minimum was –4
Maximum was 7
Rakudo Perl 6: What You Can Do Today

Problem
Find minimum and maximum values from a list
Solution (Example 2)
 my @products =
   Product.new(name => 'Beer', price => 500),
   Product.new(name => 'Wine', price => 450),
   Product.new(name => 'Vodka', price => 1600);
 say "Cheapest: " ~ @products.min(*.get_price).name;
 say "Costliest: " ~ @products.max(*.get_price).name;

Output (Example 2)
Cheapest: Wine
Costliest: Vodka
Rakudo Perl 6: What You Can Do Today

Problem
Paper, Scissor, Stone game
Solution (Part 1)
 class   Paper { }
 class   Scissor { }
 class   Stone { }
 multi   win(Paper,     Stone)     {   "Win" }
 multi   win(Scissor,   Paper)     {   "Win" }
 multi   win(Stone,     Scissor)   {   "Win" }
 multi   win(::T,       T)         {   "Draw" }
 multi   win(Any,       Any)       {   "Lose" }
Rakudo Perl 6: What You Can Do Today

Problem
Paper, Scissor, Stone game
Solution (Part 2)
 say win(Paper, Paper);
 say win(Scissor, Stone);
 say win(Stone, Scissor);

Output
Draw
Lose
Win
Rakudo Perl 6: What You Can Do Today




          Rakudo *
Rakudo Perl 6: What You Can Do Today
What is Rakudo *?
   Rakudo is making great progress
     Steadily implementing more of the spec
     Steadily passing more and more tests
     Fixing lots of bugs
     Number of active developers is growing
   So far we have been very much focused on
   building Rakudo
   Rakudo * is a release where we instead
   focus on what early adopters need
Rakudo Perl 6: What You Can Do Today
What will the release include?
   We make a compiler release every month;
   by contrast, Rakudo * is a distribution
   release including:
     The Rakudo compiler, of course ☺
     Tool for downloading, installing and
     updating modules
     A range of Perl 6 modules that help you
     achieve some common tasks (e.g. HTTP
     client/server, database connectivity, web
     things, YAML…)
Rakudo Perl 6: What You Can Do Today
What will the release include?
   We are also aiming to include a couple of
   other projects…
     Zavolaj! – a module that lets you write
     some basic pure Perl 6 bindings to C
     libraries; we built a MySQL client with it
     Blizkost – a Perl 5     Parrot bridge layer
     that will allow you to use Perl 5 modules
     from within Perl 6
Rakudo Perl 6: What You Can Do Today
What Rakudo * Will Do Well
   Rakudo has good coverage of a lot of the
   Perl 6 specification…
     Wide range of built-in operators, types and
     functions
     Subs, signatures and multiple dispatch
     Object orientation, including classes,
     roles, introspection and much more
     Perl 6 regexes and grammars (it's the
     same engine we use to parse Perl 6!)
Rakudo Perl 6: What You Can Do Today
Weaker Areas
   Rakudo * will have a lot to offer, and should
   be useful for a range of tasks
   However, it's not The Full Perl 6, and of
   course has some weak spots, including:
     Missing support for threading
     No native types support
     Fairly slow – not much work on
     optimization yet, and no optimizer
Rakudo Perl 6: What You Can Do Today
When?
   Soon ☺
Rakudo Perl 6: What You Can Do Today
When?
   Soon ☺
   Either late May or early-mid June
Rakudo Perl 6: What You Can Do Today
When?
   Soon ☺
   Either late May or early-mid June
   Yes, this year
Rakudo Perl 6: What You Can Do Today




    Get Involved!
Rakudo Perl 6: What You Can Do Today
Want to learn more?
   Get Rakudo Perl 6 from:
   http://www.rakudo.org/
   Lots of Perl 6 resources can be found at:
   http://www.perl6.org/
   Join the friendly IRC channel:
   #perl6 on irc.freenode.org
   Write modules, write applications, jump into
   the evolving Perl 6 community and make
   your mark on it ☺
Rakudo Perl 6: What You Can Do Today




       Thank You
Rakudo Perl 6: What You Can Do Today




      Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)Nikita Popov
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammarsabrummett
 
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
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+ConFoo
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPatrick Allaert
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...adrianoalmeida7
 
Security 202 - Are you sure your site is secure?
Security 202 - Are you sure your site is secure?Security 202 - Are you sure your site is secure?
Security 202 - Are you sure your site is secure?ConFoo
 
Pig Introduction to Pig
Pig Introduction to PigPig Introduction to Pig
Pig Introduction to PigChris Wilkes
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Guillaume Laforge
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesStephen Chin
 
The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.8 book - Part 96 of 202The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.8 book - Part 96 of 202Mahmoud Samir Fayed
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with itFlavien Raynaud
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model Perforce
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf
 
Invertible-syntax 入門
Invertible-syntax 入門Invertible-syntax 入門
Invertible-syntax 入門Hiromi Ishii
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3Matthew Turland
 

Was ist angesagt? (20)

PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
 
Parsing with Perl6 Grammars
Parsing with Perl6 GrammarsParsing with Perl6 Grammars
Parsing with Perl6 Grammars
 
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)
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+Marrow: A Meta-Framework for Python 2.6+ and 3.1+
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
Cypher inside out: Como a linguagem de pesquisas em grafo do Neo4j foi constr...
 
Rust ⇋ JavaScript
Rust ⇋ JavaScriptRust ⇋ JavaScript
Rust ⇋ JavaScript
 
Security 202 - Are you sure your site is secure?
Security 202 - Are you sure your site is secure?Security 202 - Are you sure your site is secure?
Security 202 - Are you sure your site is secure?
 
Spock
SpockSpock
Spock
 
Pig Introduction to Pig
Pig Introduction to PigPig Introduction to Pig
Pig Introduction to Pig
 
Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008Groovy Introduction - JAX Germany - 2008
Groovy Introduction - JAX Germany - 2008
 
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative LanguagesJavaFX Your Way: Building JavaFX Applications with Alternative Languages
JavaFX Your Way: Building JavaFX Applications with Alternative Languages
 
The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.8 book - Part 96 of 202The Ring programming language version 1.8 book - Part 96 of 202
The Ring programming language version 1.8 book - Part 96 of 202
 
How to write rust instead of c and get away with it
How to write rust instead of c and get away with itHow to write rust instead of c and get away with it
How to write rust instead of c and get away with it
 
Perl object ?
Perl object ?Perl object ?
Perl object ?
 
Perforce Object and Record Model
Perforce Object and Record Model  Perforce Object and Record Model
Perforce Object and Record Model
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective Groovy
 
Invertible-syntax 入門
Invertible-syntax 入門Invertible-syntax 入門
Invertible-syntax 入門
 
New SPL Features in PHP 5.3
New SPL Features in PHP 5.3New SPL Features in PHP 5.3
New SPL Features in PHP 5.3
 

Andere mochten auch

Andere mochten auch (7)

Met het achief op het web: 1995 tot 2011
Met het achief op het web: 1995 tot 2011Met het achief op het web: 1995 tot 2011
Met het achief op het web: 1995 tot 2011
 
Web 2.0 Revised 04/06/2007
Web 2.0 Revised  04/06/2007Web 2.0 Revised  04/06/2007
Web 2.0 Revised 04/06/2007
 
George Oates
George OatesGeorge Oates
George Oates
 
Booosting nieuwsbrief 71 (Mrt 2003)
Booosting nieuwsbrief 71 (Mrt 2003)Booosting nieuwsbrief 71 (Mrt 2003)
Booosting nieuwsbrief 71 (Mrt 2003)
 
Georgetown_student ipad considerations_11-15-2011
Georgetown_student ipad considerations_11-15-2011Georgetown_student ipad considerations_11-15-2011
Georgetown_student ipad considerations_11-15-2011
 
Welcome to CITIH 2011
Welcome to CITIH 2011Welcome to CITIH 2011
Welcome to CITIH 2011
 
14.07.2011 T2 Augmented Life Thomas Balduff Total Immersion
14.07.2011 T2 Augmented Life Thomas Balduff Total Immersion14.07.2011 T2 Augmented Life Thomas Balduff Total Immersion
14.07.2011 T2 Augmented Life Thomas Balduff Total Immersion
 

Ähnlich wie Jonathan Worthington – Perl 2010 Rit Rakudo

Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersMatthew Farwell
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10acme
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInVitaly Gordon
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Javascript development done right
Javascript development done rightJavascript development done right
Javascript development done rightPawel Szulc
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of RubyTom Crinson
 
Scala4sling
Scala4slingScala4sling
Scala4slingday
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Jeff Carouth
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopPublicis Sapient Engineering
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Adam Mukharil Bachtiar
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Naresha K
 
I need to adjust this Huffman code so that it asks for the user to i.pdf
I need to adjust this Huffman code so that it asks for the user to i.pdfI need to adjust this Huffman code so that it asks for the user to i.pdf
I need to adjust this Huffman code so that it asks for the user to i.pdfjibinsh
 
Open XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxOpen XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxPublicis Sapient Engineering
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and MonoidsHugo Gävert
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldBTI360
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tourSimon Proctor
 

Ähnlich wie Jonathan Worthington – Perl 2010 Rit Rakudo (20)

Softshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developersSoftshake 2013: 10 reasons why java developers are jealous of Scala developers
Softshake 2013: 10 reasons why java developers are jealous of Scala developers
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10
 
Scalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedInScalable and Flexible Machine Learning With Scala @ LinkedIn
Scalable and Flexible Machine Learning With Scala @ LinkedIn
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Javascript development done right
Javascript development done rightJavascript development done right
Javascript development done right
 
Hidden treasures of Ruby
Hidden treasures of RubyHidden treasures of Ruby
Hidden treasures of Ruby
 
Scala4sling
Scala4slingScala4sling
Scala4sling
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
Interpreter Case Study - Design Patterns
Interpreter Case Study - Design PatternsInterpreter Case Study - Design Patterns
Interpreter Case Study - Design Patterns
 
Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4Can't Miss Features of PHP 5.3 and 5.4
Can't Miss Features of PHP 5.3 and 5.4
 
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour HadoopOSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
OSDC.fr 2012 :: Cascalog : progammation logique pour Hadoop
 
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
Algorithm and Programming (Introduction of dev pascal, data type, value, and ...
 
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
Effective Java with Groovy & Kotlin - How Languages Influence Adoption of Goo...
 
I need to adjust this Huffman code so that it asks for the user to i.pdf
I need to adjust this Huffman code so that it asks for the user to i.pdfI need to adjust this Huffman code so that it asks for the user to i.pdf
I need to adjust this Huffman code so that it asks for the user to i.pdf
 
Open XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand DechouxOpen XKE - Big Data, Big Mess par Bertrand Dechoux
Open XKE - Big Data, Big Mess par Bertrand Dechoux
 
Introduction to Scalding and Monoids
Introduction to Scalding and MonoidsIntroduction to Scalding and Monoids
Introduction to Scalding and Monoids
 
Scala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 WorldScala vs Java 8 in a Java 8 World
Scala vs Java 8 in a Java 8 World
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Perl6 a whistle stop tour
Perl6 a whistle stop tourPerl6 a whistle stop tour
Perl6 a whistle stop tour
 

Mehr von rit2010

Sphinx new
Sphinx newSphinx new
Sphinx newrit2010
 
Microsoft cluster systems ritconf
Microsoft cluster systems ritconfMicrosoft cluster systems ritconf
Microsoft cluster systems ritconfrit2010
 
анатомия интернет банка Publish
анатомия интернет банка Publishанатомия интернет банка Publish
анатомия интернет банка Publishrit2010
 
анатомия интернет банка Publish
анатомия интернет банка Publishанатомия интернет банка Publish
анатомия интернет банка Publishrit2010
 
Anatol filin pragmatic documentation 1_r
Anatol filin  pragmatic documentation 1_rAnatol filin  pragmatic documentation 1_r
Anatol filin pragmatic documentation 1_rrit2010
 
Ilia kantor паттерны серверных comet решений
Ilia kantor паттерны серверных comet решенийIlia kantor паттерны серверных comet решений
Ilia kantor паттерны серверных comet решенийrit2010
 
Alexei shilov 2010 rit-rakudo
Alexei shilov 2010 rit-rakudoAlexei shilov 2010 rit-rakudo
Alexei shilov 2010 rit-rakudorit2010
 
Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extrarit2010
 
Konstantin kolomeetz послание внутреннему заказчику
Konstantin kolomeetz послание внутреннему заказчикуKonstantin kolomeetz послание внутреннему заказчику
Konstantin kolomeetz послание внутреннему заказчикуrit2010
 
Bykov monitoring mailru
Bykov monitoring mailruBykov monitoring mailru
Bykov monitoring mailrurit2010
 
Alexander shigin slides
Alexander shigin slidesAlexander shigin slides
Alexander shigin slidesrit2010
 
иван василевич Eye tracking и нейрокомпьютерный интерфейс
иван василевич Eye tracking и нейрокомпьютерный интерфейсиван василевич Eye tracking и нейрокомпьютерный интерфейс
иван василевич Eye tracking и нейрокомпьютерный интерфейсrit2010
 
Andrey Petrov P D P
Andrey Petrov P D PAndrey Petrov P D P
Andrey Petrov P D Prit2010
 
Andrey Petrov методология P D P, часть 1, цели вместо кейсов
Andrey Petrov методология P D P, часть 1, цели вместо кейсовAndrey Petrov методология P D P, часть 1, цели вместо кейсов
Andrey Petrov методология P D P, часть 1, цели вместо кейсовrit2010
 
Dmitry lohansky rit2010
Dmitry lohansky rit2010Dmitry lohansky rit2010
Dmitry lohansky rit2010rit2010
 
Dmitry Lohansky Rit2010
Dmitry Lohansky Rit2010Dmitry Lohansky Rit2010
Dmitry Lohansky Rit2010rit2010
 
Related Queries Braslavski Yandex
Related Queries Braslavski YandexRelated Queries Braslavski Yandex
Related Queries Braslavski Yandexrit2010
 
молчанов сергей датацентры 10 04 2010 Light
молчанов сергей датацентры 10 04 2010  Lightмолчанов сергей датацентры 10 04 2010  Light
молчанов сергей датацентры 10 04 2010 Lightrit2010
 
Sergey Ilinsky Rit 2010 Complex Gui Development Ample Sdk
Sergey Ilinsky Rit 2010 Complex Gui Development Ample SdkSergey Ilinsky Rit 2010 Complex Gui Development Ample Sdk
Sergey Ilinsky Rit 2010 Complex Gui Development Ample Sdkrit2010
 
Serge P Nekoval Grails
Serge P  Nekoval GrailsSerge P  Nekoval Grails
Serge P Nekoval Grailsrit2010
 

Mehr von rit2010 (20)

Sphinx new
Sphinx newSphinx new
Sphinx new
 
Microsoft cluster systems ritconf
Microsoft cluster systems ritconfMicrosoft cluster systems ritconf
Microsoft cluster systems ritconf
 
анатомия интернет банка Publish
анатомия интернет банка Publishанатомия интернет банка Publish
анатомия интернет банка Publish
 
анатомия интернет банка Publish
анатомия интернет банка Publishанатомия интернет банка Publish
анатомия интернет банка Publish
 
Anatol filin pragmatic documentation 1_r
Anatol filin  pragmatic documentation 1_rAnatol filin  pragmatic documentation 1_r
Anatol filin pragmatic documentation 1_r
 
Ilia kantor паттерны серверных comet решений
Ilia kantor паттерны серверных comet решенийIlia kantor паттерны серверных comet решений
Ilia kantor паттерны серверных comet решений
 
Alexei shilov 2010 rit-rakudo
Alexei shilov 2010 rit-rakudoAlexei shilov 2010 rit-rakudo
Alexei shilov 2010 rit-rakudo
 
Alexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extraAlexandre.iline rit 2010 java_fxui_extra
Alexandre.iline rit 2010 java_fxui_extra
 
Konstantin kolomeetz послание внутреннему заказчику
Konstantin kolomeetz послание внутреннему заказчикуKonstantin kolomeetz послание внутреннему заказчику
Konstantin kolomeetz послание внутреннему заказчику
 
Bykov monitoring mailru
Bykov monitoring mailruBykov monitoring mailru
Bykov monitoring mailru
 
Alexander shigin slides
Alexander shigin slidesAlexander shigin slides
Alexander shigin slides
 
иван василевич Eye tracking и нейрокомпьютерный интерфейс
иван василевич Eye tracking и нейрокомпьютерный интерфейсиван василевич Eye tracking и нейрокомпьютерный интерфейс
иван василевич Eye tracking и нейрокомпьютерный интерфейс
 
Andrey Petrov P D P
Andrey Petrov P D PAndrey Petrov P D P
Andrey Petrov P D P
 
Andrey Petrov методология P D P, часть 1, цели вместо кейсов
Andrey Petrov методология P D P, часть 1, цели вместо кейсовAndrey Petrov методология P D P, часть 1, цели вместо кейсов
Andrey Petrov методология P D P, часть 1, цели вместо кейсов
 
Dmitry lohansky rit2010
Dmitry lohansky rit2010Dmitry lohansky rit2010
Dmitry lohansky rit2010
 
Dmitry Lohansky Rit2010
Dmitry Lohansky Rit2010Dmitry Lohansky Rit2010
Dmitry Lohansky Rit2010
 
Related Queries Braslavski Yandex
Related Queries Braslavski YandexRelated Queries Braslavski Yandex
Related Queries Braslavski Yandex
 
молчанов сергей датацентры 10 04 2010 Light
молчанов сергей датацентры 10 04 2010  Lightмолчанов сергей датацентры 10 04 2010  Light
молчанов сергей датацентры 10 04 2010 Light
 
Sergey Ilinsky Rit 2010 Complex Gui Development Ample Sdk
Sergey Ilinsky Rit 2010 Complex Gui Development Ample SdkSergey Ilinsky Rit 2010 Complex Gui Development Ample Sdk
Sergey Ilinsky Rit 2010 Complex Gui Development Ample Sdk
 
Serge P Nekoval Grails
Serge P  Nekoval GrailsSerge P  Nekoval Grails
Serge P Nekoval Grails
 

Jonathan Worthington – Perl 2010 Rit Rakudo

  • 1. Rakudo Perl 6 What you can do today Jonathan Worthington РИТ++ 2010
  • 2. Rakudo Perl 6: What You Can Do Today Intro… XXX TODO
  • 3. Rakudo Perl 6: What You Can Do Today Perl 6
  • 4. Rakudo Perl 6: What You Can Do Today What is Perl 6? Take the things that make Perl great… Practical - focus on getting the job done Multi-paradigm – because there isn't one approach that's good for all problems Linguistic influences – because it's a programming language Making the easy things easy and the hard things possible
  • 5. Rakudo Perl 6: What You Can Do Today What is Perl 6? Build a new Perlish language that is… More regular – less special cases More readable and more maintainable More expressive More OO, more functional, more declarative, more parallel… Easy things even easier Harder things even more in reach
  • 6. Rakudo Perl 6: What You Can Do Today 1 Specification, Many Implementations Unlike Perl 5, Perl 6 has a written language specification No "official" implementation Like Perl 5, Perl 6 has a language test suite A conforming implementation should pass the test suite A kind of "executable specification" Currently around 40,000 tests
  • 7. Rakudo Perl 6: What You Can Do Today Rakudo
  • 8. Rakudo Perl 6: What You Can Do Today What is Rakudo? The most actively developed Perl 6 compiler Implements a large portion of the Perl 6 specification (though still some way to go) Today passing over 30,000 tests from the Perl 6 specification test suite (though the suite is still growing ☺) Currently targets the Parrot Virtual Machine Later in the year, we plan to target at least one other platform too
  • 9. Rakudo Perl 6: What You Can Do Today How Rakudo Works Written in… NQP (Bootstrapped subset of Perl 6) Compiler core (grammar and AST construction), some of the meta-model, module location/loading) Perl 6 The majority of the built-ins and operators Parrot Intermediate Language Some lower-level builtins and "glue" C Dispatchers, signature binder, other VM customizations and glue
  • 10. Rakudo Perl 6: What You Can Do Today How Rakudo Works: Parsing First, Rakudo parses your program Parser is written in Perl 6 Regexes token statement_control:sym<if> { <sym> :s <xblock> [ 'elsif's <xblock> ]* [ 'else's <else=.pblock> ]? } Some scary stuff… Might discover new operators during parse Have to run BEGIN blocks immediately
  • 11. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction Whenever we finish parsing something (for example, an if statement), we run an "action method" This builds an Abstract Syntax Tree A representation of the program that is abstracted away from the language syntax Most action methods build up a more complex AST using smaller bits made by things we already parsed
  • 12. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; }
  • 13. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Var.new( :name('$x'), :scope('lexical') )
  • 14. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Var.new( PAST::Val.new( :name('$x'), :value(42) :scope('lexical') ) )
  • 15. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( :pasttype('call'), :name('&infix:<==>'), … ) PAST::Var.new( PAST::Val.new( :name('$x'), :value(42) :scope('lexical') ) )
  • 16. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( :pasttype('call'), :name('&infix:<==>'), … ) PAST::Var.new( PAST::Val.new( :name('$x'), :value(42) :scope('lexical') ) ) PAST::Val.new( :value('The Answer!') )
  • 17. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( :pasttype('call'), :name('&infix:<==>'), … PAST::Op.new( ) :pasttype('call'), :name('&say'), … PAST::Var.new( PAST::Val.new( ) :name('$x'), :value(42) :scope('lexical') ) ) PAST::Val.new( :value('The Answer!') )
  • 18. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( PAST::Block.new( … ) :pasttype('call'), :name('&infix:<==>'), … PAST::Op.new( ) :pasttype('call'), :name('&say'), … PAST::Var.new( PAST::Val.new( ) :name('$x'), :value(42) :scope('lexical') ) ) PAST::Val.new( :value('The Answer!') )
  • 19. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( :pasttype('if'), … ) PAST::Op.new( PAST::Block.new( … ) :pasttype('call'), :name('&infix:<==>'), … PAST::Op.new( ) :pasttype('call'), :name('&say'), … PAST::Var.new( PAST::Val.new( ) :name('$x'), :value(42) :scope('lexical') ) ) PAST::Val.new( :value('The Answer!') )
  • 20. Rakudo Perl 6: What You Can Do Today How Rakudo Works: AST Construction if $x == 42 { say "The answer!"; } PAST::Op.new( :pasttype('if'), … ) PAST::Op.new( PAST::Block.new( … ) :pasttype('call'), :name('&infix:<==>'), … PAST::Op.new( ) :pasttype('call'), :name('&say'), … PAST::Var.new( PAST::Val.new( ) :name('$x'), :value(42) :scope('lexical') ) ) PAST::Val.new( :value('The Answer!') )
  • 21. Rakudo Perl 6: What You Can Do Today How Rakudo Works: Code Generation We take the AST and produce intermediate code for the target platform Today, we can only produce code in this stage for the Parrot VM Architecture means that we'll be able to add more backends in the future Can also insert optimization and program analysis phases at any point in the compilation pipeline
  • 22. Rakudo Perl 6: What You Can Do Today Examples: What You Can Do Today In Rakudo
  • 23. Rakudo Perl 6: What You Can Do Today Examples We'll look at a range of small, everyday programming problems and for each one show… The Perl 6 code that solves it The output that code gives when run Hopefully, a good way for you to start to grasp some of the new syntax and features Show of some cool Perl 6 features ☺ All examples shown today work in Rakudo
  • 24. Rakudo Perl 6: What You Can Do Today Problem Say "Hello, world" Solution say "Hello, world!" Output Hello, world!
  • 25. Rakudo Perl 6: What You Can Do Today Problem Read input from the console Solution print "Enter your name: "; my $name = $*IN.get; say "Hi $name!"; Output Enter your name: Jonathan Hi Jonathan!
  • 26. Rakudo Perl 6: What You Can Do Today Problem Check a value is in a given range Solution 1 loop { print "Enter a number from 1 to 10: "; my $num = $*IN.get; unless 1 <= $num <= 10 { say "Fail!" } } Output Enter a number between 1 and 10: 3 Enter a number between 1 and 10: 42 Fail!
  • 27. Rakudo Perl 6: What You Can Do Today Problem Check a value is in a given range Solution 2 loop { print "Enter a number from 1 to 10: "; my $num = $*IN.get; unless $num ~~ 1..10 { say "Fail!" } } Output Enter a number between 1 and 10: 3 Enter a number between 1 and 10: 42 Fail!
  • 28. Rakudo Perl 6: What You Can Do Today Problem Add up a list of numbers Solution my @nums = 1, 5, 7, -2, 3, 9, 11, -6, 14; say [+] @nums; Output 42
  • 29. Rakudo Perl 6: What You Can Do Today Problem Check if a list is sorted Solution my @a = 1, 1, 2, 3, 5, 8; my @b = 9, 4, 1, 16, 36, 25; if [<=] @a { say '@a is sorted' } if [<=] @b { say '@b is sorted' } Output @a is sorted
  • 30. Rakudo Perl 6: What You Can Do Today Problem Iterate over a list Solution my @cities = <Lisbon Tokyo Seoul Riga>; for @cities -> $city { say "I've been to $city"; } Output I've been to Lisbon I've been to Tokyo I've been to Seoul I've been to Riga
  • 31. Rakudo Perl 6: What You Can Do Today Problem Iterate over the keys and values of a hash Solution my %distances = Bratislava => 1084, Stockholm => 442; for %distances.kv -> $city, $distance { say "$city is $distance km away"; } Output Bratislava is 1084 km away Stockholm is 442 km away
  • 32. Rakudo Perl 6: What You Can Do Today Problem Check if any of a list of test scores is a pass Solution my @a = 75, 47, 90, 22, 80; my @b = 61, 77, 94, 82, 60; my @c = 45, 59, 33, 11, 19; if any(@a) >= 60 { say "Some passes in A" } if any(@b) >= 60 { say "Some passes in B" } if any(@c) >= 60 { say "Some passes in C" } Output Some passes in A Some passes in B
  • 33. Rakudo Perl 6: What You Can Do Today Problem Check if all of a list of test scores are passes Solution my @a = 75, 47, 90, 22, 80; my @b = 61, 77, 94, 82, 60; my @c = 45, 59, 33, 11, 19; if all(@a) >= 60 { say "All passes in A" } if all(@b) >= 60 { say "All passes in B" } if all(@c) >= 60 { say "All passes in C" } Output All passes in B
  • 34. Rakudo Perl 6: What You Can Do Today Problem Check if none of a list of test scores is a pass Solution my @a = 75, 47, 90, 22, 80; my @b = 61, 77, 94, 82, 60; my @c = 45, 59, 33, 11, 19; if none(@a) >= 60 { say "No passes in A" } if none(@b) >= 60 { say "No passes in B" } if none(@c) >= 60 { say "No passes in C" } Output No passes in C
  • 35. Rakudo Perl 6: What You Can Do Today Problem Get a random item from a list Solution my @drinks = <wine beer vodka>; say "Tonight I'll drink { @drinks.pick }"; Output (results should vary ;-)) Tonight I'll drink vodka
  • 36. Rakudo Perl 6: What You Can Do Today Problem Shuffle a list into a random order Solution my @competitors = <Tina Lena Owen Peter>; my @order = @competitors.pick(*); for @order { .say } Output (results should vary ;-)) Peter Lena Owen Tina
  • 37. Rakudo Perl 6: What You Can Do Today Problem Write and call a subroutine with parameters Solution sub greet($greeting, $name) { say "$greeting, $name!"; } greet("hello", "masak"); Output hello, masak
  • 38. Rakudo Perl 6: What You Can Do Today Problem Write a subroutine that only takes a number Solution sub double(Num $n) { 2 * $n } say double(21); say double("oh no I'm not a number"); Output 42 Parameter type check failed; expected Num, but got Str for $n in call to double
  • 39. Rakudo Perl 6: What You Can Do Today Problem Use multi-subs to react differently by type Solution multi double(Num $n) { 2 * $n } multi double(Str $s) { $s x 2 } say double(21); say double("boo"); Output 42 booboo
  • 40. Rakudo Perl 6: What You Can Do Today Problem Compute factorial (recursively) Solution multi fact($n) { $n * fact($n - 1) } multi fact(0) { 1 } say fact(1); say fact(10); Output 1 3628800
  • 41. Rakudo Perl 6: What You Can Do Today Problem Compute factorial (using a meta-operator) Solution sub fact($n) { [*] 1..$n } say fact(1); say fact(10); Output 1 3628800
  • 42. Rakudo Perl 6: What You Can Do Today Problem Add a new factorial operator (so 10! works) Solution sub postfix:<!>($n) { [*] 1..$n } say 1!; say 10!; Output 1 3628800
  • 43. Rakudo Perl 6: What You Can Do Today Problem Declare a class with attributes and a method Solution class Product { has $.name; # Attr + accessor has $!price; # Attr only has $.discount is rw; # Attr + lvalue accessor method get_price { return $!price - $!discount; } }
  • 44. Rakudo Perl 6: What You Can Do Today Problem Instantiate a class and call a method on it Solution my $prod = Product.new( name => "Beer", price => 500, discount => 60 ); say $prod.get_price; Output 440
  • 45. Rakudo Perl 6: What You Can Do Today Problem Get/set attributes through accessors Solution say $prod.name; $prod.discount = 40; say $prod.get_price; $prod.name = 'Wine'; Output Beer 460 Cannot assign to readonly variable.
  • 46. Rakudo Perl 6: What You Can Do Today Problem Call a method on every object in a list Solution my @products = Product.new(name => 'Beer', price => 500), Product.new(name => 'Wine', price => 450), Product.new(name => 'Vodka', price => 1600); my @uc_names = @products>>.name>>.uc; for @uc_names { .say } Output BEER WINE VODKA
  • 47. Rakudo Perl 6: What You Can Do Today Problem Introspect a class to find its methods Solution my @meths = Product.^methods(:local); for @meths>>.name { .say } Output get_price discount name
  • 48. Rakudo Perl 6: What You Can Do Today Problem Sort an array of objects by result of a method Solution (Example 1) my @products = Product.new(name => 'Beer', price => 500), Product.new(name => 'Wine', price => 450), Product.new(name => 'Vodka', price => 1600); my @sorted = @products.sort(*.name); for @sorted { .name.say } Output (Example 1) Beer Vodka Wine
  • 49. Rakudo Perl 6: What You Can Do Today Problem Sort an array of objects by result of a method Solution (Example 2) my @products = Product.new(name => 'Beer', price => 500), Product.new(name => 'Wine', price => 450), Product.new(name => 'Vodka', price => 1600); my @sorted = @products.sort(*.get_price); for @sorted { .name.say } Output (Example 2) Wine Beer Vodka
  • 50. Rakudo Perl 6: What You Can Do Today Problem Find minimum and maximum values from a list Solution (Example 1) my @temperatures = -3, 5, 7, 2, -1, -4, 0; say "Minimum was " ~ @temperatures.min; say "Maximum was " ~ @temperatures.max; Output (Example 1) Minimum was –4 Maximum was 7
  • 51. Rakudo Perl 6: What You Can Do Today Problem Find minimum and maximum values from a list Solution (Example 2) my @products = Product.new(name => 'Beer', price => 500), Product.new(name => 'Wine', price => 450), Product.new(name => 'Vodka', price => 1600); say "Cheapest: " ~ @products.min(*.get_price).name; say "Costliest: " ~ @products.max(*.get_price).name; Output (Example 2) Cheapest: Wine Costliest: Vodka
  • 52. Rakudo Perl 6: What You Can Do Today Problem Paper, Scissor, Stone game Solution (Part 1) class Paper { } class Scissor { } class Stone { } multi win(Paper, Stone) { "Win" } multi win(Scissor, Paper) { "Win" } multi win(Stone, Scissor) { "Win" } multi win(::T, T) { "Draw" } multi win(Any, Any) { "Lose" }
  • 53. Rakudo Perl 6: What You Can Do Today Problem Paper, Scissor, Stone game Solution (Part 2) say win(Paper, Paper); say win(Scissor, Stone); say win(Stone, Scissor); Output Draw Lose Win
  • 54. Rakudo Perl 6: What You Can Do Today Rakudo *
  • 55. Rakudo Perl 6: What You Can Do Today What is Rakudo *? Rakudo is making great progress Steadily implementing more of the spec Steadily passing more and more tests Fixing lots of bugs Number of active developers is growing So far we have been very much focused on building Rakudo Rakudo * is a release where we instead focus on what early adopters need
  • 56. Rakudo Perl 6: What You Can Do Today What will the release include? We make a compiler release every month; by contrast, Rakudo * is a distribution release including: The Rakudo compiler, of course ☺ Tool for downloading, installing and updating modules A range of Perl 6 modules that help you achieve some common tasks (e.g. HTTP client/server, database connectivity, web things, YAML…)
  • 57. Rakudo Perl 6: What You Can Do Today What will the release include? We are also aiming to include a couple of other projects… Zavolaj! – a module that lets you write some basic pure Perl 6 bindings to C libraries; we built a MySQL client with it Blizkost – a Perl 5 Parrot bridge layer that will allow you to use Perl 5 modules from within Perl 6
  • 58. Rakudo Perl 6: What You Can Do Today What Rakudo * Will Do Well Rakudo has good coverage of a lot of the Perl 6 specification… Wide range of built-in operators, types and functions Subs, signatures and multiple dispatch Object orientation, including classes, roles, introspection and much more Perl 6 regexes and grammars (it's the same engine we use to parse Perl 6!)
  • 59. Rakudo Perl 6: What You Can Do Today Weaker Areas Rakudo * will have a lot to offer, and should be useful for a range of tasks However, it's not The Full Perl 6, and of course has some weak spots, including: Missing support for threading No native types support Fairly slow – not much work on optimization yet, and no optimizer
  • 60. Rakudo Perl 6: What You Can Do Today When? Soon ☺
  • 61. Rakudo Perl 6: What You Can Do Today When? Soon ☺ Either late May or early-mid June
  • 62. Rakudo Perl 6: What You Can Do Today When? Soon ☺ Either late May or early-mid June Yes, this year
  • 63. Rakudo Perl 6: What You Can Do Today Get Involved!
  • 64. Rakudo Perl 6: What You Can Do Today Want to learn more? Get Rakudo Perl 6 from: http://www.rakudo.org/ Lots of Perl 6 resources can be found at: http://www.perl6.org/ Join the friendly IRC channel: #perl6 on irc.freenode.org Write modules, write applications, jump into the evolving Perl 6 community and make your mark on it ☺
  • 65. Rakudo Perl 6: What You Can Do Today Thank You
  • 66. Rakudo Perl 6: What You Can Do Today Questions?