Sub::Lambda

Sub::Lambda is a syntactic sugar for lambdas in Perl.
Download

Sub::Lambda Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Anton Tayanovskyy
  • Publisher web site:
  • http://search.cpan.org/~toyvo/Sub-Lambda-0.02/lib/Sub/Lambda.pm

Sub::Lambda Tags


Sub::Lambda Description

Sub::Lambda is a syntactic sugar for lambdas in Perl. Sub::Lambda is a syntactic sugar for lambdas in Perl.SYNOPSIS use Sub::Lambda; *plus = fn a => fn b => '$a + $b'; my $minus = fn a => fn b => q{ $a - $b }; *flip = fn f => fn a => fn b => ap qw(f b a); *sum = fn h => -t => q{ @t ? $h+sum(@t) : ($h || 0) }; print plus(1)->(2) . "n"; # 3 = 1 + 2 print $minus->(10)->(5) . "n"; # 5 = 10 - 5 print flip($minus)->(10)->(5) . "n"; # -5 = 5 - 10 print sum(1,2,3,4) . "n"; # 10 = 1+2+3+4 my $fac = fn f => fn n => q{ ($n($n-1) }; my $Y = fn m => ap( (fn f => ap m => fn a => ap f => f => a => ()) => (fn f => ap m => fn a => ap f => f => a => ()) ); print $Y->($fac)->(5) . "n"; # 120 = 5!DESCRIPTION ^This module provides syntactic sugar for lambda abstractions and applications. Perl supports lambdas through subroutine references. You can write things like the curried addition: sub { my ($x) = @_; sub { my ($y) = @_; $x + $y } }However, this is not very convenient nor readable for more involved lambda expressions. Contrast this with the sugared syntax for the same function: fn x => fn y => q{ $x + $y }If you would like even more convenience at the expense of somewhat unclear semantics, check out the experimental Sub::Lambda::Filter module, with which you could write: ( x -> y -> {$x+$y} )Requirements:· Perl Requirements: · Perl


Sub::Lambda Related Software