-
-
Notifications
You must be signed in to change notification settings - Fork 475
Closed
Description
I know this would be a tricky to implement or may require some workaround. The question actually quite simple: With the following expression structure, how to get arithmetic result along with evaluation result?
<ARITHMATRIC EXPRESSION> <OPERATOR> <VALUE>
For example, what's best to way to return the value of foo+bar+baz = 6 with true evaluation result?
package main
import (
"fmt"
"github.com/antonmedv/expr"
)
func main() {
env := map[string]interface{}{
"foo": 1,
"bar": 2,
"baz": 3,
}
code := `foo + bar + baz > 5`
program, err := expr.Compile(code, expr.Env(env))
if err != nil {
panic(err)
}
output, err := expr.Run(program, env)
if err != nil {
panic(err)
}
fmt.Println(output)
}I know this is a way too open to bugs and unexpected cases, but still, any workaround or ideas here? What should I do?
Metadata
Metadata
Assignees
Labels
No labels