Successfully reported this slideshow.
Your SlideShare is downloading. ×

Nigel hamilton-megameet-2013

More Related Content

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Nigel hamilton-megameet-2013

  1. 1. Perl6 – Am I Bovvered?
  2. 2. say “Hello” … X Factor
  3. 3. Hello Earthling???!!!
  4. 4. But the Genius® at the Apple Store told me it would connect!!??
  5. 5. Who has the X Factor? puts “Hello!” 'Hello!' printNl. print(“Hello!”); System.out.println(“Hello!”); “Am I Bovvered?”
  6. 6. “Yeah But No But Yeah” public class HelloWorld { public static void main(String[] args) { System.out.println("Hello!"); } }
  7. 7. (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!”;
  8. 8. Perl5 <=> Perl6 →
  9. 9. linguistics ~ comp sci Larry Wall ~~ Cunning Linguist
  10. 10. Rosetta Stone Code http://rosettacode.org ● A+ to ZED ● 501 Languages ● Hundreds of Tasks
  11. 11. Expressitivity    # Perl5 old Skool sub factorial { my $n = shift; my $result = 1; for (my $i = 1; $i <= $n; ++$i) { $result *= $i; }; $result; }
  12. 12. Iterative / Recursive / Declarative? Expressive sub postfix:<!> { [*] 1 .. $^n } say 5!; # prints 120  
  13. 13. [Meta] WAT? ­ operators on operators
  14. 14. [Reduction Meta Operator] my @numbers = 1 .. 3; say [+] @numbers; say [max] @numbers; say [min] @numbers; say [~] @numbers; say [>] @numbers; say [<] @numbers; say [>] @numbers.reverse;   
  15. 15. [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
  16. 16. [Reduction Meta Operator] my @numbers = 1 .. 3; say [+] @numbers; say [max] @numbers; say [min] @numbers; say [~] @numbers; say [>] @numbers; say [<] @numbers; say [>] @numbers.reverse;   
  17. 17. 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♣ ♡ ♣ ♠ ♠
  18. 18. 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>
  19. 19. 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>
  20. 20. 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"; }
  21. 21. 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
  22. 22. 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 ...
  23. 23. 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
  24. 24. 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
  25. 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}"; } } }
  26. 26. 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;
  27. 27. -O Fun camelia => http://perl6.org
  28. 28. Rosetta Stone Code http://rosettacode.org ● A+ to ZED ● 501 Languages ● Hundreds of Tasks

×