Git Product home page Git Product logo

abacus's People

Contributors

h4cc avatar jamesewatkins avatar mryawe avatar narrowtux avatar q60 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

abacus's Issues

Introduce a simple function to check expression syntax

Easy one.

Is it possible to introduce Abacus.syntax?/[1,2] function, returning {:ok} / {:error, extended_info}? It might be quite handy in case of deferred operations. In my use case, I accept an expression as, say, user input, and execute it later on some alert. I would appreciate having an ability to inform the user that the expression introduced has syntax glitches.

I could provide a pull request for just this feature, but I think it’s up to you to decide whether you want to use it also in eval/[1,2], or not.

Accept `.2` and `2.` as floats

Currently the formula’s parser fails with:

{:error, {1, :math_term_parser, ['syntax error before: ', '\'.\'']}}

on floats with omitted leading/trailing zero (.25 / 2..) It is quite common to have floats being written that way, so I would suggest it makes sense to accept this notation.

Design unit system

TODO

  • Registry for unit strings to their definitions
    • Possibility to use aliases (for example meter to m)
  • Prepare lexer and parser to parse unit expressions
    • m / s should be parsed as {:divide, {:unit, "m"}, {:unit, "s"}}
  • Add second parser-pass to map {:unit, binary} to a unit definition
  • Change eval/2 functions to support multiplication operations (/, *, ^) on amounts
  • Support SI prefixes (m, k, M, ...)
  • function to convert units

Better error reports

The parser should be improved so that we can extract the line and column where a syntax error happened in the input.

With this, error reports like the following should be possible:

Input: 1+)
         ^
Unexpected Token '('.

What needs to be done for this:

  • Pass the column of a symbol when lexing
  • Put this column into the error when the lexer or the parser have a problem
  • Get the correct message out of parser errors

BItwise support

  • Bitshift >> <<
  • & | |^ ~ (and or xor not)

TODO

  • Parse to AST
  • Write eval code
  • Write formatter
  • Test all 3

Eval() function return type for boolean expression

This is just a cosmetic thing, but maybe interesting for others...

The dialyzer is complaining about the eval function and a boolean expression. According to the docs, the return type is always a number(), which is not correct in the case of an boolean expression evaluation. There the return value is an atom(), 'true' or 'false'.
So is there a way to tell the eval function that we have an boolean return value? Or change the return value in general to any()?

Support strings coercion in scope

iex(1)> Abacus.eval "a>5", %{"a" => 4.5}
{:ok, false}
iex(2)> Abacus.eval "a>5", %{"a" => "4.5"}
{:ok, true}

Of course, I can do a coercion to respective Float before evaling, but people expect this to be done by abacus :)

I believe, the coercion might be easily done here. Please confirm, and I will provide the pull request.
Thanks in advance.

Support Polish Notation

Supporting Polish Notation would be a cool addition to this library in my opinion. Or a polish notation evaluation library may be a idea for another math library? But I dont know how something like this would be done. Just throwing the idea out here.

https://en.wikipedia.org/wiki/Polish_notation

Thanks for reading my issue!

Support elixir functions

Offer registering own functions by name in runtime, so they can be called in a abacus expression.

Possibility to disable certain features

Hey!

Our use case only involves evaluating basic maths and floating point manipulation functions - we would love to be able to disable the evaluation of things we don't need, such as factorial, bitwise, comparison, boolean operators, Enum API, etc.

Do you know of any way we could achieve that right now, and if not, would it be possible to add such a configuration option to the library? For example, a "whitelist" of operations.

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.