Giter Site home page Giter Site logo

infix's Issues

Add memoizing evaluator

Using evaluate is good for readability: the evaluated expression appears in the code where it is executed. Using compile is good for execution speed: parsing of both the expression and the contained constants gets to happen ahead of time. The presumed "hot code path" is thus optimized.

Can we get both?

A memoizing evaluator could probably achieve a speedup when compared to evaluate as well as an improvement in readability compared to compile. It would look just like evaluate but internally use some memoization, maybe like this:

var memoizedExpressions = {};

function memoizingEvaluator(expression, numberProvider) {
    var f = memoizedExpressions[expression];
    if (!f) f = memoizedExpressions[expression] = compile(expression, numberProvider);
    return f();
}

Add `evaluate` which doesn't accept placeholders

The basic arithmetic syntax can be useful for accepting user input. For this use case, it is confusing that placeholders are accepted. infix could offer a version of evaluate which does not accept placeholders to solve this use case.

It makes less sense to have this version of the compiler. Compiled expressions mostly make sense with placeholders. So, it is sufficient only to implement the requisite evaluate function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.