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.
THE JOY OF SIX
Nigel Hamilton + Team
Lean Software Development + Training
Bath, United Kingdom
http://nigelhamilton.com
ni...
First a confession ...
THE JOY OF SEX
OMG – It's THIS Christmas!!!
O(fun)
Jonathan Worthington
“Perl6: my most
learningist project”
Jnthn++
Wetware <=> Hardware
O(fun) needs Cognitive Comfort
PCRE
^(?:[0-9]{1,3}.){3}[0-9]{1,3}$
Fear is a Flow killer
^(?:[0-9]{1,3}.){3}[0-9]{1,3}$
Human-friendly Regex Parsing
my $flavour-of-perl = 'Perl 6';
say 'Perl 5 regex matches'
if $flavour-of-perl ~~ m:P5/Perl [...
Regex Revamp
my $ip = '213.120.160.146';
if $ip ~~ m:P5/^(?:[0-9]{1,3}.){3}[0-9]{1,3}$/ {
say 'Perl 5 regex matches';
}
if...
Ramping Regexen
my token digits {
(<digit>**1..3) <?{ $0 < 256 }>
};
my rule ip-address {
<digits> '.' <digits> '.' <digit...
Grammar Time!
grammar IP::Address {
token TOP { <v4> }
token v4 {
<digits> '.' <digits> '.' <digits> '.' <digits>
}
token ...
Comb the Logs
use IP::Address;
my $logs = 'Check these version 4 IPs: 213.120.160.146,
12.10.12.13';
my @ips = $logs.comb(...
Rosetta Stone Code
A+ to ZED
596 Languages
Hundreds of Tasks
Where Larry Wall has
O(fun)
http://rosettacode.org
Whipupitude + Expressivity
Whipupitude
// Java
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the ter...
Whipupitude
#!/usr/bin/env perl6
#| deploy to a node by name
sub MAIN ($node-name) {
say "deploying now to node $node-name...
Whipupitude
use IP::Address;
#| deploy to a node by name
multi sub MAIN ($node-name) {
say "deploying to node: $node-name"...
Expressivity
# Perl5 old Skool
sub factorial {
my $n = shift;
my $result = 1;
for (my $i = 1; $i <= $n; ++$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...
[Reduction Meta Operator]
my @numbers = 1 .. 3;
say [+] @numbers; # 6
say [max] @numbers; # 3
say [min] @numbers; # 1
say ...
X product – Meta Operator
my @suits = <♣ ♢ ♡ ♠>;
my @ranks = flat 1..10,'J','Q','K','A';
my @deck = @ranks X~ @suits;
my @...
Lean Coding ...
BOSS: “I need dates for all the last Fridays of the month for
this year”
Lean programmer grabs a highlight...
Python's Last Friday (14 LOC)
import calendar
c=calendar.Calendar()
fridays={}
year=raw_input("year")
for item in c.yearda...
Last Friday in Perl 6 (7 LOC)
sub MAIN (Int :$year = Date.today.year) {
my @fri;
for Date.new("$year-01-01") .. Date.new("...
Whipupitude + Expressivity
Discover the Joy of Six
The O(fun) must Flow!
Go to http://perl6.org and
http://perl6intro.com
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Joy of Six - Discover the Joy of Perl 6
Upcoming SlideShare
Loading in …5
×

Joy of Six - Discover the Joy of Perl 6

386 views

Published on

Passionate programmers have discovered how coding in Perl Six can be playful, imaginative, pleasurable and exhilarating.

This talk includes tasteful illustrations for curious monoglot and polyglot programmers alike.

Discover the Joy of Six!

Published in: Software
  • Be the first to comment

  • Be the first to like this

Joy of Six - Discover the Joy of Perl 6

  1. 1. THE JOY OF SIX Nigel Hamilton + Team Lean Software Development + Training Bath, United Kingdom http://nigelhamilton.com nige@nigelhamilton.com
  2. 2. First a confession ...
  3. 3. THE JOY OF SEX
  4. 4. OMG – It's THIS Christmas!!!
  5. 5. O(fun)
  6. 6. Jonathan Worthington “Perl6: my most learningist project” Jnthn++
  7. 7. Wetware <=> Hardware
  8. 8. O(fun) needs Cognitive Comfort
  9. 9. PCRE ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$
  10. 10. Fear is a Flow killer ^(?:[0-9]{1,3}.){3}[0-9]{1,3}$
  11. 11. Human-friendly Regex Parsing my $flavour-of-perl = 'Perl 6'; say 'Perl 5 regex matches' if $flavour-of-perl ~~ m:P5/Perl [56]/; say 'Perl 6 regex matches' if $flavour-of-perl ~~ m:i/perl s <[56]>/; ;
  12. 12. Regex Revamp my $ip = '213.120.160.146'; if $ip ~~ m:P5/^(?:[0-9]{1,3}.){3}[0-9]{1,3}$/ { say 'Perl 5 regex matches'; } if $ip ~~ /^[<digit> ** 1..3] ** 4 % '.'$/ { say 'Perl 6 regex matches'; }
  13. 13. Ramping Regexen my token digits { (<digit>**1..3) <?{ $0 < 256 }> }; my rule ip-address { <digits> '.' <digits> '.' <digits> '.' <digits>
  14. 14. Grammar Time! grammar IP::Address { token TOP { <v4> } token v4 { <digits> '.' <digits> '.' <digits> '.' <digits> } token digits { (d**1..3) <?{ $0 < 256 }> } }
  15. 15. Comb the Logs use IP::Address; my $logs = 'Check these version 4 IPs: 213.120.160.146, 12.10.12.13'; my @ips = $logs.comb(/<IP::Address::v4>/); IPv6 too? http://rosettacode.org/wiki/Parse_an_IP_Address#Perl_6
  16. 16. Rosetta Stone Code A+ to ZED 596 Languages Hundreds of Tasks Where Larry Wall has O(fun) http://rosettacode.org
  17. 17. Whipupitude + Expressivity
  18. 18. Whipupitude // Java public class HelloWorld { public static void main(String[] args) { // Prints "Hello, World" to the terminal System.out.println("Hello, World"); } } # Perl 6 say 'Hello, World'; 'Hello, World'.say;
  19. 19. Whipupitude #!/usr/bin/env perl6 #| deploy to a node by name sub MAIN ($node-name) { say "deploying now to node $node-name"; } shell> ./deploy.p6 -help Usage: ./deploy.p6 <node-name> -- deploy to a node by name
  20. 20. Whipupitude use IP::Address; #| deploy to a node by name multi sub MAIN ($node-name) { say "deploying to node: $node-name"; } #| deploy to a specific IP address multi sub MAIN ($node-ip where { $_ ~~ /<IP::Address::v4>/ }) { say "deploying to ip address: $node-ip"; } shell> ./deploy.p6 -help Usage: ./deploy.p6 <node-name> -- deploy to a node by name ./deploy.p6 <node-ip> -- deploy to a specific IP address
  21. 21. Expressivity # Perl5 old Skool sub factorial { my $n = shift; my $result = 1; for (my $i = 1; $i <= $n; ++$i) { $result *= $i; }; return $result; }
  22. 22. Iterative / Recursive / Declarative? Expressive sub postfix:<!> { [*] 1 .. $^n } say 5!; # prints 120
  23. 23. [Meta] WAT? - operators on operators
  24. 24. [Reduction Meta Operator] my @numbers = 1 .. 3; say [+] @numbers; say [max] @numbers; say [min] @numbers; say [~] @numbers; say [>] @numbers; say [<] @numbers; say [>] @numbers.reverse;
  25. 25. [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
  26. 26. X product – Meta Operator my @suits = <♣ ♢ ♡ ♠>; my @ranks = flat 1..10,'J','Q','K','A'; my @deck = @ranks X~ @suits; my @hand = @deck.pick(5); say @hand; shell> perl6 hand.p6 7♣ 5♡ 2♣ J♠ 10♠
  27. 27. Lean Coding ... BOSS: “I need dates for all the last Fridays of the month for this year” Lean programmer grabs a highlighter pen and a calendar. BOSS: “Oh, and for any year out of the last 20” Lean programmer opens up a terminal window … and types ...
  28. 28. 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
  29. 29. Last Friday in Perl 6 (7 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]; } shell> perl6 last-friday.p6 --help Usage: last-friday.p6 [--year=<Int>] shell> perl6 last-friday.p6 2015-12-25
  30. 30. Whipupitude + Expressivity
  31. 31. Discover the Joy of Six
  32. 32. The O(fun) must Flow!
  33. 33. Go to http://perl6.org and http://perl6intro.com

×