diff options
| -rw-r--r-- | go/src/step2_eval/step2_eval.go | 22 | ||||
| -rw-r--r-- | go/src/types/types.go | 16 |
2 files changed, 38 insertions, 0 deletions
diff --git a/go/src/step2_eval/step2_eval.go b/go/src/step2_eval/step2_eval.go index 4aededa..e82c360 100644 --- a/go/src/step2_eval/step2_eval.go +++ b/go/src/step2_eval/step2_eval.go @@ -36,6 +36,28 @@ func eval_ast(ast MalType, env map[string]MalType) (MalType, error) { lst = append(lst, exp) } return List{lst}, nil + } else if Vector_Q(ast) { + lst := []MalType{} + for _, a := range ast.(Vector).Val { + exp, e := EVAL(a, env) + if e != nil { return nil, e } + lst = append(lst, exp) + } + return Vector{lst}, nil + } else if Hash_Map_Q(ast) { + m := ast.(map[string]MalType) + new_hm := map[string]MalType{} + for k, v := range m { + ke, e1 := EVAL(k, env) + if e1 != nil { return nil, e1 } + if _, ok := ke.(string); !ok { + return nil, errors.New("non string hash-map key") + } + kv, e2 := EVAL(v, env) + if e2 != nil { return nil, e2 } + new_hm[ke.(string)] = kv + } + return new_hm, nil } else { return ast, nil } diff --git a/go/src/types/types.go b/go/src/types/types.go index e3d8163..9fcc78c 100644 --- a/go/src/types/types.go +++ b/go/src/types/types.go @@ -34,3 +34,19 @@ func List_Q(obj MalType) bool { default: return false } } + +// Vectors +func Vector_Q(obj MalType) bool { + switch obj.(type) { + case Vector: return true + default: return false + } +} + +// Hash Maps +func Hash_Map_Q(obj MalType) bool { + switch obj.(type) { + case map[string]MalType: return true + default: return false + } +} |
