func ExampleWithEnvironment() { env := makeEnv() // Create evaluation environment result, panik, compileErrs := eval.EvalEnv(`fmt.Sprintf("%s %d", constant1, add(var1, 1) + 1)`, env) _ = panik _ = compileErrs fmt.Printf("%+v\n", result[0].Interface()) }
// goEval runs eval.EvalEnv in a new goroutine. This is a quick hack to // keep the debugger from pausing while running eval.EvalEnv. func goEval(expr string, env eval.Env) (result []reflect.Value, panik error, compileErrors []error) { c := make(chan struct{}) go func() { defer close(c) result, panik, compileErrors = eval.EvalEnv(expr, env) }() <-c return }
// goEval runs eval.EvalEnv in a new goroutine. This is a quick hack to // keep the debugger from pausing while running eval.EvalEnv. // It is also used to recover from panics in the eval library. func goEval(expr string, env eval.Env) (result []reflect.Value, panik error, compileErrors []error) { c := make(chan struct{}) go func() { defer func() { if r := recover(); r != nil { panik = fmt.Errorf("%v", r) } close(c) }() result, panik, compileErrors = eval.EvalEnv(expr, env) }() <-c return }