Perl6 – Am I Bovvered?
say “Hello” … X Factor
Hello Earthling???!!!
But the Genius® at the Apple Store
told me it would connect!!??
Who has the X Factor?
puts “Hello!”
'Hello!' printNl.
print(“Hello!”);
System.out.println(“Hello!”);
“Am I Bovvered?”
“Yeah But No But Yeah”
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello!");
}
}
(format t "Hello!~%")
#include <iostream>
int main () {
std::cout << "Hello!" << std::endl;
return std::cout.bad();
}
“Stop giving me evils!”
console.log("Hello!");
say “Hello!”;
Perl5 <=> Perl6
→
linguistics ~ comp sci
Larry Wall ~~ Cunning Linguist
Rosetta Stone Code
http://rosettacode.org
● A+ to ZED
● 501 Languages
● Hundreds of Tasks
Expressitivity
   # Perl5 old Skool
sub factorial {
my $n = shift;
my $result = 1;
for (my $i = 1; $i <= $n; ++$i) {
$result *= $i;
};
$result;
}
Iterative / Recursive / Declarative?
Expressive
sub postfix:<!> { [*] 1 .. $^n }
say 5!; # prints 120
 
[Meta] WAT?
­ operators on operators
[Reduction Meta Operator]
my @numbers = 1 .. 3;
say [+] @numbers;
say [max] @numbers;
say [min] @numbers;
say [~] @numbers;
say [>] @numbers;
say [<] @numbers;
say [>] @numbers.reverse;   
[Reduction Meta Operator]
my @numbers = 1 .. 3;
say [+] @numbers; # 6
say [max] @numbers; # 3
say [min] @numbers; # 1
say [~] @numbers; # 123
say [>] @numbers; # False
say [<] @numbers; # True
say [>] @numbers.reverse; # True
[Reduction Meta Operator]
my @numbers = 1 .. 3;
say [+] @numbers;
say [max] @numbers;
say [min] @numbers;
say [~] @numbers;
say [>] @numbers;
say [<] @numbers;
say [>] @numbers.reverse;   
X product – Meta Operator
my @suits  = <       >;♣ ♢ ♡ ♠
my @ranks  = 2..10, <J Q K A>;
my @deck   = @ranks X~ @suits;
my @hand   = @deck.pick(5);
say @hand;
nige@hammer:~/megameet­talk$ perl6 
hand.p6 
7  5  2  J  10♣ ♡ ♣ ♠ ♠
Whipupitude
multi sub MAIN ($number-of-nodes) {
say "deploy to: $number-of-nodes nodes";
}
nige@hammer:~/megameet-talk$ perl6 deploy.p6
Usage:
deploy.p6 <number-of-nodes>
Whipupitude
multi sub MAIN (Int $number-of-nodes) {
say "deploy to: $number-of-nodes nodes";
}
nige@hammer:~/megameet-talk$ perl6 deploy.p6 live
Usage:
deploy.p6 <number-of-nodes>
Whipupitude
multi sub MAIN (Int $number-of-nodes) {
say "deploy to: $number-of-nodes nodes";
}
multi sub MAIN (Bool :$run-tests?,
Str :$cluster ='staging') {
say "running tests" if $run-tests;
say "deploying to cluster: $cluster-name";
}
Whipupitude
nige@hammer:~/megameet-talk$ perl6 deploy.p6 --help
Usage:
deploy.p6 <number-of-nodes>
deploy.p6 [--run-tests] [--cluster-name=<Str>]
nige@hammer:~/megameet-talk$ perl6 deploy.p6 --run-
tests --cluster=live
running tests
deploying to cluster: live
Utility
BOSS: “I need dates for all the last Fridays 
of the month for this year”
Agile programmer grabs a highlighter and a 
calendar.
BOSS: “Oh, and for any year out of the last 
20”
Agile programmer opens up a terminal window … 
and types ...
Python's Last Friday (14 LOC)
import calendar
c=calendar.Calendar()
fridays={}
year=raw_input("year")
for item in c.yeardatescalendar(int(year)):
for i1 in item:
for i2 in i1:
for i3 in i2:
if "Fri" in i3.ctime() and year in
i3.ctime():
month,day=str(i3).rsplit("-",1)
fridays[month]=day
Last Friday in Perl6 (5 LOC)
sub MAIN (Int :$year = Date.today.year) {
my @fri;
for Date.new("$year-01-01") .. Date.new("$year-12-31"){
@fri[.month] = .Str if .day-of-week == 5;
}
.say for @fri[1..12];
}
nige@hammer:~/megameet-talk$ perl6 date.p6 --help
Usage:
date.p6 [--year=<Int>]
nige@hammer:~/megameet-talk$ perl6 date.p6
2013-01-25
Simple Search Engine
Inverted Index (11 LOC)
sub MAIN (*@files) {
(my %norm).push: do for @files -> $file {
$file X=> slurp($file).lc.words;
}
(my %inv).push: %norm.invert.uniq;
while prompt("Search terms: ").words -> @words {
for @words -> $word {
say "$word => %inv.{$word.lc}";
}
}
}
Oh my god that is so unfair!
package org.rosettacode;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-O Fun camelia => http://perl6.org
Rosetta Stone Code
http://rosettacode.org
● A+ to ZED
● 501 Languages
● Hundreds of Tasks

Nigel hamilton-megameet-2013