likebike / fasteval

Fast and safe evaluation of algebraic expressions
https://crates.io/crates/fasteval/
MIT License
275 stars 27 forks source link

Add REPL binary target #1

Open Stupremee opened 4 years ago

Stupremee commented 4 years ago

It would be great if you could provide a binary target which is a REPL to quickly perform calculations in the command line.

I would work on this issue if you accpet it

likebike commented 4 years ago

I already have a REPL in the 'examples' directory: https://github.com/likebike/fasteval/blob/master/examples/repl.rs

It can be run like this: rlwrap cargo run --release --example repl

Were you thinking of something different? I'd be happy to consider your ideas.

likebike commented 4 years ago

One constraint is that I don't want to add too many dependencies to 'fasteval'. But a REPL really needs a good 'readline' user interface. That's why I structured this to be wrapped with 'rlwrap'.

One possible solution would be to make another 'fasteval-repl' crate which uses the 'fasteval' library, but produces a repl binary. This way, dependencies like readline can be isolated from 'fasteval'.

Do you have other ideas?

Stupremee commented 4 years ago

That’s exactly what I thought of. I saw the example and created my own binary but it’s much easier if you provide a fasteval REPL crate.

likebike commented 4 years ago

If you want to create a REPL crate, that's fine with me. I personally don't want to create an official REPL right now because it would actually take a lot of work to create a really really good REPL. You see, fasteval is actually a very capable library; The REPL that I provide as an example barely "scratches the surface" of fasteval's abilities. If I made a REPL, I would want to include advanced functionality, like the ability to create user-defined functions at run-time, and I would probably want to implement additional number types besides f64 (I'd probably want BitInteger support, along with cryptography functions, and I'd probably want Rational numbers too. Oh! and definitely complex numbers!)...

In other words, creating a great REPL is really a lot of work. If we just create a very-simple REPL (like the example), then I don't think it's actually useful for anything -- it's not an interesting product. Python and bc are already better. That's why I feel it deserves an example, but not an official crate at this point.

likebike commented 4 years ago

I'll create an official REPL after we have Advanced Numeric Types:

Update: I created #7 to track this goal.

Stupremee commented 4 years ago

Okay. Thanks for the information.

Ujang360 commented 4 years ago

@likebike I'm sharing my fasteval-repl with my friends (cargo install conveniency). I will take it down if you do mind or when you implemented Advanced Numeric Types or when the official REPL is going to be published.

I will understand if you mind for the name and thank you @likebike for your great library :pray:

likebike commented 4 years ago

@Ujang360 I don't mind at all. Thanks for doing this!

In the future, once fasteval is more mature, I think we can make and even better REPL. But for now, this is a good solution.