What's the best way to evaluate a string containing a mathematical expression while following order of operations?
Say for example you have `let expr: &str = "14 + 10 / 2 - 3 * 5` which should evaluate to `4`.
What's the best way of doing this via rust? My first inclination is to split the string by the lower-precedence operations (`+` & `-`), evaluate the substrings (which will then contain either `*` or `/`) and then sum/subtract up those results. The only way I can think of doing this is via higher-order functions like `fold()`. Does anyone else have alternative suggestions?
https://redd.it/hi14zo
@r_rust
Say for example you have `let expr: &str = "14 + 10 / 2 - 3 * 5` which should evaluate to `4`.
What's the best way of doing this via rust? My first inclination is to split the string by the lower-precedence operations (`+` & `-`), evaluate the substrings (which will then contain either `*` or `/`) and then sum/subtract up those results. The only way I can think of doing this is via higher-order functions like `fold()`. Does anyone else have alternative suggestions?
https://redd.it/hi14zo
@r_rust