Last active
October 15, 2017 00:52
-
-
Save lamarmarshall/99f7d64fded92a2356b0e72ffc77e9da to your computer and use it in GitHub Desktop.
golang ,eval parse math , commanf line arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"strings" | |
"github.com/apaxa-go/eval" | |
) | |
func main() { | |
str := os.Args[1] | |
exp := strings.Replace(str, "x", "*", -1) | |
expr, _ := eval.ParseString(exp, "") | |
r, _ := expr.EvalToInterface(nil) | |
fmt.Printf("%v %T", r, r) // "3 int8" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment