Your SlideShare is downloading. ×
0
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Functional perl
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Functional perl

1,112

Published on

Unpolished talk on functional concepts in perl.

Unpolished talk on functional concepts in perl.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,112
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Functional Programming Perl Christopher Mckay error@errorific.com
  • 2. What Am I
  • 3. Whats this talk all about?
  • 4. History
  • 5. How
  • 6. Why not?
  • 7. But I dont use/appreciate/like perl?
  • 8. Functional Programming is Easy
  • 9. So easy sysadmins do it
  • 10. In the beginning...
  • 11. Wrote Pearl Perl
  • 12. People wanted a sort function Larry was generous
  • 13. sortF(a, a), [a] --------> [a]
  • 14. @sorted_list = sort {$_[0] <=> $_[1]} @list
  • 15. @sorted_list = sort {$a <=> $b } @list
  • 16. @sorted_list = sort {$a <=> $b} @list
  • 17. sort String sortingsort {$a cmp $b} Also string sortingsort {$a <=> $b} Sort numericallysort &comparator Sort by function named comparator
  • 18. sort { @a = split ///, $a; @b = split ///, $b; ($a[2] <=> $b[2]) || ($a[1] <=> $b[1]) || ($a[0] <=> $b[0]) || 0;} @list_of_dmy_dates
  • 19. 1988 - Perl 2.01989 - Perl 3.01991 - Perl 4.0
  • 20. grepF(a, a), [a] --------> [a]
  • 21. mapF(a), [a] --------> [a]
  • 22. 1994 – Perl 5.0
  • 23. memoizeF(a) → b --------------> F(a) → b
  • 24. List::Util reduceF(a, b) → b, [a] --------------> b
  • 25. List::MoreUtilsany, all, none, notall, true, false, firstidx, first_index, lastidx, part, mesh,last_index, insert_after, zip, uniq, apply, indexes, after, after_incl, before, before_incl, firstval, first_value, lastval, last_value, pairwise, distinct, minmax
  • 26. So Perl evolved a functional theme
  • 27. So how do I make functional stuff in perl instead of just using it?
  • 28. Lexical scoping
  • 29. First class functions
  • 30. Thats about it.Your language does that too right?
  • 31. So lets write a function that rolls a die
  • 32. my $dx = sub { my ($sides) = @_; return (rand() * $sides) + 1;}my $roll = $dx->(6);
  • 33. I dont like rolling 1s though so...
  • 34. my $cheat = sub { my ($roll) = @_; if ($roll < 2) { return 2; } else { return $roll; }}
  • 35. I dont want to get caught turning the die over though so ...
  • 36. my $inconspicuous_dx = sub { my ($sides) = @_; return $cheat->($dx->($sides));}
  • 37. my $compose = sub { my ($fa, $fb) = @_; return sub { return $fa->($fb->(@_)); }}
  • 38. my $inconspicuous_dx = $compose->($cheat, $dx);my $better_roll = $inconspicuous_dx->(6);
  • 39. Monads in PerlMasahiro Honma (hiratara) YAPC::Asia 2011 Slides are in english Data::Monad
  • 40. All I ever need is d6!
  • 41. my $d6 = sub { return $inconspicuous_dx->(6);};my $roll_a_6 = $d6->();
  • 42. Too lazy to roll 20d6
  • 43. my $dice_tower_maker = sub { my ($die) = @_; return sub { my ($rolls) = @_; return map { $die->() } (1 .. $rolls); }}
  • 44. my $dice_tower = $dice_tower_generator->($d6);say join(, , $dice_tower->(20));
  • 45. use List::Util;say sum $dice_tower->(20);
  • 46. use List::Util;say reduce {$a + $b} $dice_tower->(20);
  • 47. So why not use this stuff for everything?
  • 48. The compilers not out to help you
  • 49. Declaring functions gets obtuse after awhile
  • 50. Purity isnt an option, everything changes
  • 51. The community loves objects
  • 52. If it was simple in a functionallanguage it probably takes some hacking to make it work in perl
  • 53. And the language isnt extensible, yet
  • 54. Good things are to come
  • 55. Perl 6
  • 56. Static typing Better syntax Blocks and closures List comprehensionAutomatic parallelisation Lots more
  • 57. ThanksQuestions?

×