Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Nigel hamilton-megameet-2013

809 views

Published on

Perl6 is fast approaching. This talk invites early-adopting, polyglot programmers to start taking a deeper look.

Published in: Technology, Business
  • Be the first to comment

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 Storetold 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 sciLarry Wall ~~ Cunning Linguist
  10. 10. Rosetta Stone Codehttp://rosettacode.org● A+ to ZED● 501 Languages● Hundreds of Tasks
  11. 11. Expressitivity   # Perl5 old Skoolsub factorial {my $n = shift;my $result = 1;for (my $i = 1; $i <= $n; ++$i) {$result *= $i;};$result;}
  12. 12. Iterative / Recursive / Declarative?Expressivesub 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; # 6say [max] @numbers; # 3say [min] @numbers; # 1say [~] @numbers; # 123say [>] @numbers; # Falsesay [<] @numbers; # Truesay [>] @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 Operatormy @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. Whipupitudemulti sub MAIN ($number-of-nodes) {say "deploy to: $number-of-nodes nodes";}nige@hammer:~/megameet-talk$ perl6 deploy.p6Usage:deploy.p6 <number-of-nodes>
  19. 19. Whipupitudemulti sub MAIN (Int $number-of-nodes) {say "deploy to: $number-of-nodes nodes";}nige@hammer:~/megameet-talk$ perl6 deploy.p6 liveUsage:deploy.p6 <number-of-nodes>
  20. 20. Whipupitudemulti 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. Whipupitudenige@hammer:~/megameet-talk$ perl6 deploy.p6 --helpUsage:deploy.p6 <number-of-nodes>deploy.p6 [--run-tests] [--cluster-name=<Str>]nige@hammer:~/megameet-talk$ perl6 deploy.p6 --run-tests --cluster=liverunning testsdeploying to cluster: live
  22. 22. UtilityBOSS: “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. Pythons Last Friday (14 LOC)import calendarc=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 ini3.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 --helpUsage:date.p6 [--year=<Int>]nige@hammer:~/megameet-talk$ perl6 date.p62013-01-25
  25. 25. Simple Search EngineInverted 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 Codehttp://rosettacode.org● A+ to ZED● 501 Languages● Hundreds of Tasks

×