rekka / meval-rs

Math expression parser and evaluation library for Rust
The Unlicense
153 stars 30 forks source link

Boolean comparisons? #16

Closed markschl closed 2 years ago

markschl commented 6 years ago

I've been looking at a Rust alternative for ExprTK, and meval seems like a good and simple library. However, I wonder if you would ever consider implementing boolean operators? In ExprTK, booleans don't exist as separate type (as far as I understand), comparisons just evaluate to 0 or 1, which makes it probably quite simple to implement. Thank you very much.

rekka commented 6 years ago

Thanks for your interest in meval, and for the suggestion. I never really meant for it to become anything fancier than a simple evaluation of math functions for setting up numerical computations and such. I feel like boolean operators do not quite fit this. I prefer strongly typed expressions (that's why I like Rust), so having boolean operators returning 0. and 1. feels a bit strange :)

For piece-wise defined functions, it is usually sufficient to use abs, max, min, signum... And it often expresses the intent more clearly. I might consider adding functions like step and sign, but it's also easy to add them as custom functions.

For a much more powerful scripting language, there is dyon for instance.

markschl commented 6 years ago

Thanks, I understand that it feels a bit strange mixing the types that way. My question was a very pragmatic one; I would need this for evaluating a simple filter expression many times with different values for the variables. I might have to create bindings for ExprTK (which is not so easy)... Actually, I could also define custom comparison functions returning 0. or 1., but that's not very intuitive to use.

rekka commented 2 years ago

It looks like https://crates.io/crates/evalexpr is a possible alternative