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

NAME

Perinci::Sub::Gen::FromFormulas - Generate functions from formulas

VERSION

This document describes version 0.001 of Perinci::Sub::Gen::FromFormulas (from Perl distribution Perinci-Sub-Gen-FromFormulas), released on 2017-03-14.

FUNCTIONS

gen_funcs_from_formulas

Usage:

 gen_funcs_from_formulas(%args) -> [status, msg, result, meta]

Generate functions from formulas.

Examples:

  • Example #1:

     gen_funcs_from_formulas(
     formulas => [
                     { formula => "fv = pv*(1+r)**n" },
                     { formula => "pv = fv/(1+r)**n" },
                     { formula => "r = (fv/pv)**(1/n) - 1" },
                     { formula => "n = log(fv/pv) / log(1+r)" },
                   ],
       symbols  => {
                     n  => {
                             summary => "Number of periods",
                             schema  => "float*",
                             caption => "periods",
                           },
                     r  => {
                             caption => "return rate",
                             summary => "Return rate (e.g. 0.06 or 6%)",
                             schema  => "float*",
                           },
                     fv => { schema => "float*", caption => "future value" },
                     pv => { schema => "float*", caption => "present value" },
                   },
       prefix   => "calc_fv_"
     );

This routine helps make creating function (and accompanying Rinci metadata) from formula less tedious.

This function is not exported by default, but exportable.

Arguments ('*' denotes required arguments):

  • formulas* => array

  • install => bool (default: 1)

    Whether to install generated functions (and metadata).

    By default, generated functions will be installed to the specified (or caller's) package, as well as its generated metadata into %SPEC. Set this argument to false to skip installing.

  • package => str

    Generated function's package, e.g. `My::Package`.

    This is needed mostly for installing the function. You usually don't need to supply this if you set install to false.

    If not specified, caller's package will be used by default.

  • symbols* => hash

Returns an enveloped result (an array).

First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error). Second element (msg) is a string containing error message, or 'OK' if status is 200. Third element (result) is optional, the actual result. Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: A hash of function names and function coderef and metadata (hash)

HOMEPAGE

Please visit the project's homepage at https://metacpan.org/release/Perinci-Sub-Gen-FromFormulas.

SOURCE

Source repository is at https://github.com/perlancar/perl-Perinci-Sub-Gen-FromFormulas.

BUGS

Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Sub-Gen-FromFormulas

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

SEE ALSO

Rinci

Other function generators: Perinci::Sub::Gen::AccessTable.

AUTHOR

perlancar <perlancar@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.