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.
Rakudo 楽土
Polyglot Programming DC 2014
Brock Wilcox
awwaiid@thelackthereof.org
bwilcox@optoro.com
Big language. Lots of stuff.
Object Oriented (Ruby, CLOS)
Data/Function Oriented (Haskell, Clojure)
Operator Oriented (APL, J)
Sigil Oriented (Ruby, Pe...
Normal Stuff
Fancy Stuff
Insane Stuff
Normal Stuff
· Garbage collected
· Curley, semi-colony
· Class object system
· Roles (like interfaces, mixins, traits)
· Scalars, lists...
class Animal { }
class Dog is Animal { }
role Logging { }
class Dog does Logging { }
class Person {
has $.name;
has $.age;
method say-hi {
say "I am the great $.name! I am $.age years old.";
}
}
my $joe = Pe...
Sigils / Twigls
$joe # scalar
$!name # private instance var
$.name # public instance var kinda
@people # list
%phonebook # hash
&lookup # ...
Scalars, Lists, Hashes
my @names = ('Casey', 'Dakota', 'Jaiden', 'Jordan', 'Peyton');
my @names = <Casey Dakota Jaiden Jordan Peyton>;
say "Third...
my %ages = {
Casey => 5,
Dakota => 10,
Jaiden => 15,
};
say "Jaiden is %ages{'Jaiden'}";
say "Jaiden is %ages<Jaiden>";
Ruby-style DSL blocks
sub doit(&thing) {
say "I say...";
&thing();
}
doit { say "hello" }
Closures / Lambdas
sub counter {
my $n = 1;
-> { $n++ };
}
my &counter_1 = counter();
my &counter_2 = counter();
say &counter_1(); # 1
say &c...
Fancy Stuff
· Optional Static Typing
· Introspection and MOP
· Advanced subroutine argument declarations
· Multi dispatch (both type a...
my $x = "fishies"
my Int $x = "fishies" # ERROR
sub add_only_ints(Int $x, Int $y) {
$x + $y
}
Multi-dispatch
(pattern matching)
multi sub add_stuff(Int $x, Int $y) {
$x + $y
}
multi sub add_stuff(Str $x, Str $y) {
$x ~ $y
}
Meta Programming / Introspection
# Get the class
say 3.WHAT # (Int)
# Get the heirarchy
3.^mro
# Get the methods
3.^methods
Insane(ly awesome) Stuff
· Operator overloading
· Meta/Hyper operators
· Chained comparisons
· Adverbs
· Grammars
· Junction values
· Unixy MAIN
· ...
Operator-Oriented
5 + 7
Meta/Hyper Operators
$x += 5
$x -= 5
$x *= 5
$x /= 5
my $x = 5
$x = $x.is-prime
$x .= is-prime
[+] <5 7 23 21 32>
# 88
<1 2 3 4> <<+>> <5 6 7 8>
# 6 8 10 12
<1 2 3 4> «+» <5 6 7 8>
# 6 8 10 12
<1 2 3 4> «*» <5 6 7 8>
# 5 12 21 32
User-defined operators
sub infix:<⋄> ($a, $b) {
$a >= $b ?? $a !! $b;
# or: $a max $b
}
17 ⋄ 42
my $x = 7;
$x ⋄= 3;
sub postfix:<!>($n) {
[*] 2..$n;
}
6! # 720
"I swear the only reason we don’t have factorial
as a standard operator in the language, is so
that we can impress people ...
type position syntax
====== ========== ========
prefix before a term !X
infix between two terms X ! Y
postfix after a term...
Get a list of all builtin infix operators
CORE::.keys.grep(/infix/)>>.say
Show all the multi dispatches for '+'
&[+].candidates>>.say
Random Stuff
2 < $x < 10
$x = 5|7
if $x == 5 { say "yep" } else { say "nope" }
$x = 5&7
if $x.is-prime { say "yep" } else { say "nope" }
@stuff.map: { $^a + 2 }
@stuff.map: { $^fish + $^sticks }
-> $x { $x + 2 }
<2 3 4 5 4> <<+>> 2
<2 3 4 5 4>.map: -> $x { $x + 2 }
<2 3 4 5 4>.map: * + 2
use MONKEY_TYPING;
augment class Int {
method infix:<⋄> ($v) {
self min $v
}
}
In-progress features:
· Non-blocking IO
· Inline concurrency
· Autothreading
· Advanced macros
· Improving JVM integration
THE END
Oh yeah. Almost forgot.
Rakudo is an implementation of Perl6
Upcoming SlideShare
Loading in …5
×

Rakudo

589 views

Published on

I demonstrate a small slice of Rakudo, an implementation of a dynamic language with some advanced features.

During the actual talk I used the REPL to do live demonstrations, often taking suggestions from the audience.

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

Rakudo

  1. 1. Rakudo 楽土 Polyglot Programming DC 2014 Brock Wilcox awwaiid@thelackthereof.org bwilcox@optoro.com
  2. 2. Big language. Lots of stuff.
  3. 3. Object Oriented (Ruby, CLOS) Data/Function Oriented (Haskell, Clojure) Operator Oriented (APL, J) Sigil Oriented (Ruby, Perl) Optional Static Typing (Common Lisp) Multi Dispatch (Clojure, Haskell)
  4. 4. Normal Stuff Fancy Stuff Insane Stuff
  5. 5. Normal Stuff
  6. 6. · Garbage collected · Curley, semi-colony · Class object system · Roles (like interfaces, mixins, traits) · Scalars, lists, hashes, sets · Block scoping, closures, anon funcs
  7. 7. class Animal { } class Dog is Animal { }
  8. 8. role Logging { } class Dog does Logging { }
  9. 9. class Person { has $.name; has $.age; method say-hi { say "I am the great $.name! I am $.age years old."; } } my $joe = Person.new( name => 'Joe', age => 37 ); $joe.say-hi
  10. 10. Sigils / Twigls
  11. 11. $joe # scalar $!name # private instance var $.name # public instance var kinda @people # list %phonebook # hash &lookup # callable block
  12. 12. Scalars, Lists, Hashes
  13. 13. my @names = ('Casey', 'Dakota', 'Jaiden', 'Jordan', 'Peyton'); my @names = <Casey Dakota Jaiden Jordan Peyton>; say "Third: @names[2]" say @names.join(", ");
  14. 14. my %ages = { Casey => 5, Dakota => 10, Jaiden => 15, }; say "Jaiden is %ages{'Jaiden'}"; say "Jaiden is %ages<Jaiden>";
  15. 15. Ruby-style DSL blocks
  16. 16. sub doit(&thing) { say "I say..."; &thing(); } doit { say "hello" }
  17. 17. Closures / Lambdas
  18. 18. sub counter { my $n = 1; -> { $n++ }; } my &counter_1 = counter(); my &counter_2 = counter(); say &counter_1(); # 1 say &counter_1(); # 2 say &counter_2(); # 1 say &counter_2(); # 2
  19. 19. Fancy Stuff
  20. 20. · Optional Static Typing · Introspection and MOP · Advanced subroutine argument declarations · Multi dispatch (both type and value based) · Generators · Lazy evaluated lists · Partial application / currying · Concurrent multi-version module usage
  21. 21. my $x = "fishies" my Int $x = "fishies" # ERROR
  22. 22. sub add_only_ints(Int $x, Int $y) { $x + $y }
  23. 23. Multi-dispatch (pattern matching)
  24. 24. multi sub add_stuff(Int $x, Int $y) { $x + $y } multi sub add_stuff(Str $x, Str $y) { $x ~ $y }
  25. 25. Meta Programming / Introspection
  26. 26. # Get the class say 3.WHAT # (Int) # Get the heirarchy 3.^mro # Get the methods 3.^methods
  27. 27. Insane(ly awesome) Stuff
  28. 28. · Operator overloading · Meta/Hyper operators · Chained comparisons · Adverbs · Grammars · Junction values · Unixy MAIN · Macros · Whatever-star · Placeholder variables
  29. 29. Operator-Oriented
  30. 30. 5 + 7
  31. 31. Meta/Hyper Operators
  32. 32. $x += 5 $x -= 5 $x *= 5 $x /= 5
  33. 33. my $x = 5 $x = $x.is-prime $x .= is-prime
  34. 34. [+] <5 7 23 21 32> # 88
  35. 35. <1 2 3 4> <<+>> <5 6 7 8> # 6 8 10 12
  36. 36. <1 2 3 4> «+» <5 6 7 8> # 6 8 10 12 <1 2 3 4> «*» <5 6 7 8> # 5 12 21 32
  37. 37. User-defined operators
  38. 38. sub infix:<⋄> ($a, $b) { $a >= $b ?? $a !! $b; # or: $a max $b } 17 ⋄ 42
  39. 39. my $x = 7; $x ⋄= 3;
  40. 40. sub postfix:<!>($n) { [*] 2..$n; } 6! # 720
  41. 41. "I swear the only reason we don’t have factorial as a standard operator in the language, is so that we can impress people by defining it." - Carl Mäsak
  42. 42. type position syntax ====== ========== ======== prefix before a term !X infix between two terms X ! Y postfix after a term X! circumfix around [X] postcircumfix after & around X[Y]
  43. 43. Get a list of all builtin infix operators CORE::.keys.grep(/infix/)>>.say
  44. 44. Show all the multi dispatches for '+' &[+].candidates>>.say
  45. 45. Random Stuff
  46. 46. 2 < $x < 10
  47. 47. $x = 5|7 if $x == 5 { say "yep" } else { say "nope" }
  48. 48. $x = 5&7 if $x.is-prime { say "yep" } else { say "nope" }
  49. 49. @stuff.map: { $^a + 2 } @stuff.map: { $^fish + $^sticks }
  50. 50. -> $x { $x + 2 }
  51. 51. <2 3 4 5 4> <<+>> 2 <2 3 4 5 4>.map: -> $x { $x + 2 } <2 3 4 5 4>.map: * + 2
  52. 52. use MONKEY_TYPING; augment class Int { method infix:<⋄> ($v) { self min $v } }
  53. 53. In-progress features: · Non-blocking IO · Inline concurrency · Autothreading · Advanced macros · Improving JVM integration
  54. 54. THE END
  55. 55. Oh yeah. Almost forgot.
  56. 56. Rakudo is an implementation of Perl6

×