0xfaded / eval

BSD 3-Clause "New" or "Revised" License
34 stars 7 forks source link

API: a simple eval() function that rolls in parse and type check into the eval. #46

Closed rocky closed 10 years ago

rocky commented 10 years ago

Currently we have:

env := &eval.Env { ... }
ctx := &eval.Ctx{"..."}
if expr, err := parser.ParseExpr(line); err != nil {
        fmt.Printf("parse error: %s\n", err)
} else if cexpr, errs := eval.CheckExpr(ctx, expr, env); len(errs) != 0 {
    for _, cerr := range errs {
        fmt.Printf("%v\n", cerr)
    }
} else if vals, _, err := eval.EvalExpr(ctx, cexpr, env); err != nil {
    fmt.Printf("eval error: %s\n", err)
}

I think we want something that removes explicit ParseExpr and CheckExpr calls. That is something like:

env := &eval.Env { ... }
if vals, _, err := eval.EvalString("...", env); err != nil {
    fmt.Printf("eval error: %s\n", err)
}
0xfaded commented 10 years ago

Agree, I also plan to remove the context

Carl 2014/01/27 2:42 "R. Bernstein" notifications@github.com:

Currently we have:

env := &eval.Env { ... } ctx := &eval.Ctx{"..."} if expr, err := parser.ParseExpr(line); err != nil { fmt.Printf("parse error: %s\n", err) } else if cexpr, errs := eval.CheckExpr(ctx, expr, env); len(errs) != 0 { for , cerr := range errs { fmt.Printf("%v\n", cerr) } } else if vals, , err := eval.EvalExpr(ctx, cexpr, env); err != nil { fmt.Printf("eval error: %s\n", err) }

I think we want something that removes explicit ParseExpr and CheckExpr calls. That is something like:

env := &eval.Env { ... } if vals, _, err := eval.EvalString("...", env); err != nil { fmt.Printf("eval error: %s\n", err) }

— Reply to this email directly or view it on GitHubhttps://github.com/0xfaded/eval/issues/46 .