Closed NatanFreeman closed 1 year ago
What is your use-case? What do you need that for?
I wanted to make a simple calculator with user input. Is this library not designed for such a use-case?
At the moment there is no support for assignment to variables in strings to be parsed. If you really want to use Exmex for your calculator, you currently have to build some logic around Exmex to track the variables yourself. Maybe one could add a method FlatEx::assign
that returns a new expression to Exmex with the following behavior.
let expr_1 = exmex::parse::<f64>("x^2+y^2+z^2")?;
// variables x and y are turned into constants
let expr_2 = expr_1.assign("x=2;y=2");
// expr_2 only depends on z, since x and y are fixed.
assert!((expr_2.eval(&[4]) - 16.0).abs() < 1e-12);
where the right hand side of =
always needs to be an expression without variables. Then a calculator app (that allows users to assign values to variables) would need to detect whether a user input string is an assignment or something that should be evaluated. But it wouldn't need to parse the assignment.
I would be able to define =
as a binary operator using the MakeOperators
trait if it weren't for the fact that make
cannot return additional information such as variable assignment.
Yes. Operators cannot be used for that.
Are there any plans to change the current behaviour to address this?
To change what precisely?
Adding detection for assignment. Is this in scope of the project?
I have currently no plans. I might put more thought into this.
I'm closing this issue as the current state of implementing this isn't planned to change. This is a very impressive crate even as it stands. I look forward to seeing how it develops.
I was wondering if there was an idiomatic may to have variables with user defined values that prissiest between calculations. Similar to how evalexpr handles things.
Theoretical usage: