The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

FP::noLazy - make lazy syntax non-lazy

SYNOPSIS

    use FP::noLazy; # instead of: use FP::Lazy;

    eval {
        lazy { 1 / 0 };
    };
    like $@, qr/division by zero/;

    my $x = lazy { 123*456 };
    ok !is_promise $x; # currently; see 'BUGS'
    is $x, 56088;

DESCRIPTION

Lazy evaluation is very useful to change the valuation order in purely functional programs. It can also make debugging confusing, as the order in which lazy expressions are evaluated depends on how they are being used, unlike in non-lazy (eager, imperative) programming, where evaluation order is directly visible from reading the program code.

For this reason, it can be helpful to temporarily disable lazy evaluation. This can mean that a program isn't as efficient as it would be, that it allocates lots of memory, or even runs out of memory, but seeing how it behaves may point out the programming error. So this is one tool to debug lazy functional programs. (Other tools are enabing debug mode, see "DEBUGGING" in FP::Lazy to see the contexts in which promises were created, splitting the program into smaller pieces, adding warn statements.)

Turning off lazy evaluation globally can be problematic, since it also changes e.g. FP::Stream or FP::IOStream to evaluate eagerly, which can lead to the program running out of memory before reaching the stages to be debugged. Changing `lazy` to `lazy_if` (from FP::Lazy) can be tedious. Importing `lazy` (and the other lazy forms) from FP::noLazy instead of FP::Lazy turns all lazy statements in the current module to normal non-lazy (eager) ones, i.e. the program then behaves as if the lazy forms weren't used at all. You can now debug the program "as normal".

BUGS

As mentioned above, your program can use more memory or run out of memory when using this module. If that happens, instead go back to using FP::Lazy and instead use `lazy_if` selectively to track down the bugs.

`lazy` etc. from this module don't (currently) wrap the result of the computation in a promise. This means that `is_promise` will return false. This could lead your program to behave differently, although maybe that should be considered a bug in your program. If you think otherwise, please tell, and this module could be changed to still use promise wrappers (even though they are already-evaluated). (It would also be possible to configure this behaviour.)

SEE ALSO

FP::Lazy

NOTE

This is alpha software! Read the status section in the package README or on the website.