From 3bd216c75bf528cc647cec5ba569dae0ccf8fe6d Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Sun, 21 Oct 2012 01:03:36 -0400 Subject: [PATCH] fixed evaluation order problem in sexp --- skeam.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/skeam.go b/skeam.go index 3017e0e..f3290a5 100644 --- a/skeam.go +++ b/skeam.go @@ -120,14 +120,8 @@ func eval(v interface{}, env *environment) (interface{}, error) { return nil, errors.New("illegal evaluation of empty sexp ()") } - // get first element as symbol - s, ok := t[0].(symbol) - if !ok { - return nil, errors.New("expected a symbol") - } - - // resolve symbol - v, err := env.get(s) + // eval the first item + v, err := eval(t[0], env) if err != nil { 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 len(t) > 1 { return l.call(env, t[1:]) @@ -182,7 +177,7 @@ func evalall(c chan token, env *environment) { } } default: - fmt.Println("error in eval: %v", err) + fmt.Printf("error in eval: %v\n", err) } } }