Sub::DeferredPartial is a deferred evaluation / partial application.
SYNOPSIS
use Sub::DeferredPartial 'def';
$S = def sub : P1 P2 P3 { %_=@_; join '', @_{qw(P1 P2 P3)} };
print $S->( P1 => 1, P2 => 2, P3 => 3 )->(); # 123
$A = $S->( P3 => 1 ); # partial application
$B = $S->( P3 => 2 );
$C = $A + $B; # deferred evaluation
$D = $C->( P2 => 3 );
$E = $D->( P1 => 4 );
print $E->(); # force evaluation: 863
$F = $E - $D;
$G = $F->( P1 => 0 ) / 2;
print $G->(); # 400
print $G; # ( ( CODE(0x15e3818): P1 => 4, P2 => 3, P3 => 1 + CODE ...
$F->(); # Error: Free parameter : P1
$A->( P3 => 7 ); # Error: Bound parameter: P3
$A->( P4 => 7 ); # Error: Wrong parameter: P4
An instance of this class behaves like a sub (or, more precisely: subroutine reference), but it supports partial application and the evaluation of operators applied to such function objects is deferred too.
That means, evaluation has to be forced explicitly (which makes it easier to add introspection capabilities).
Objects that represent deferred (delayed, suspended) expressions are known as suspensions or thunks in various programming circles. Don't confuse with the same terms in the context of threads!
Requirements:
· Perl
Product's homepage
Requirements:
· Perl