CPS
view release on metacpan or search on metacpan
Note that the returned wrapper function only has one continuation slot in its
arguments. It therefore cannot be used as the body for C<kloop()>,
C<kforeach()> or C<kgenerate()>, because these pass two continuations. There
does not exist a "natural" way to lift a normal call/return function into a
CPS function which requires more than one continuation, because there is no
way to distinguish the different named returns.
=cut
sub liftk(&)
{
my ( $code ) = @_;
return sub {
my $k = pop;
@_ = $code->( @_ );
goto &$k;
};
}
asynchronisation or event-driven framework). For C<dropk> to actually work in
this situation, it requires a way to run the event framework, to cause it to
process events until the continuation has been invoked.
This is provided by the block, or the first passed CODE reference. When the
returned function is invoked, it repeatedly calls the block or wait function,
until the CPS function has invoked its continuation.
=cut
sub dropk(&$)
{
my ( $waitfunc, $kfunc ) = @_;
return sub {
my @result;
my $done;
$kfunc->( @_, sub { @result = @_; $done = 1 } );
while( !$done ) {
( run in 1.479 second using v1.01-cache-2.11-cpan-49f99fa48dc )