Dear fellow monks,

I'm preparing my first CPAN module, which is a parser and evaluator for mathematical expressions.

I know there are some modules like that no CPAN, but Math::Expr says in section Bugs "The parses does not handle bad strings in a decent way. If you try to parse a string that does not follow the specification above, all strange things might happen..." which scares me. And Math::Expression and Math::Calculus::Expression seem both fine, but they are overkill when I simply want to parse and evaluate numerical expressions.

Anyway, what I am looking for is a good name. Currently I consider Math::Lite::Expression or Math::Eval. Do you have better suggestions, or even better ideas?

Secondly I am looking for advise on the interface.

Currently it looks like this (in examples):

# does what you think: print Math::Light::Expression->new("2*3")->val(); # force the statement delimiter to be ';'. # otherwise it's optional, and whitespaces # delimit expressions my $m = Math::Light::Expression->new({force_semicolon => 1}); $m->parse("a = 2; a^(a+b)")->val({ b => 3}); # arguments to val() overwrite variables in statements: $m->parse("a=1; a*2")->val({ a => -1 }); # result: -2

Is there anything that could be improved?

(Update: fixed typo)

Update: thank you for your input, everybody.

I named my module Math::Expression::Evaluator now and uploaded it to cpan.


In reply to RFC: Module for evaluation math. expressions by moritz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.