Skip to content

Instantly share code, notes, and snippets.

@lamarmarshall
Last active October 15, 2017 00:52
Show Gist options
  • Save lamarmarshall/99f7d64fded92a2356b0e72ffc77e9da to your computer and use it in GitHub Desktop.
Save lamarmarshall/99f7d64fded92a2356b0e72ffc77e9da to your computer and use it in GitHub Desktop.
golang ,eval parse math , commanf line arguments
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