fixed evaluation order problem in sexp

master
Jordan Orelli 12 years ago
parent 51a27aaa9b
commit 3bd216c75b

@ -120,14 +120,8 @@ func eval(v interface{}, env *environment) (interface{}, error) {
return nil, errors.New("illegal evaluation of empty sexp ()") return nil, errors.New("illegal evaluation of empty sexp ()")
} }
// get first element as symbol // eval the first item
s, ok := t[0].(symbol) v, err := eval(t[0], env)
if !ok {
return nil, errors.New("expected a symbol")
}
// resolve symbol
v, err := env.get(s)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -150,6 +144,7 @@ func eval(v interface{}, env *environment) (interface{}, error) {
} }
} }
// exec lambda if possible
if l, ok := v.(lambda); ok { if l, ok := v.(lambda); ok {
if len(t) > 1 { if len(t) > 1 {
return l.call(env, t[1:]) return l.call(env, t[1:])
@ -182,7 +177,7 @@ func evalall(c chan token, env *environment) {
} }
} }
default: default:
fmt.Println("error in eval: %v", err) fmt.Printf("error in eval: %v\n", err)
} }
} }
} }

Loading…
Cancel
Save