diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-04 23:16:19 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-10-04 23:16:19 -0500 |
| commit | 8b8afefc458810da516272d679b5a9de1f0daa17 (patch) | |
| tree | b2d9fd4e4863c61230df31e592f5f6e35325b837 /go/src/step2_eval | |
| parent | 5caa8fb7e0bc5ebe1c2ec2df7b0ae1cc4ceeff8d (diff) | |
| download | mal-8b8afefc458810da516272d679b5a9de1f0daa17.tar.gz mal-8b8afefc458810da516272d679b5a9de1f0daa17.zip | |
go: step2_eval vector/hash-map in eval_ast
Diffstat (limited to 'go/src/step2_eval')
| -rw-r--r-- | go/src/step2_eval/step2_eval.go | 22 |
1 files changed, 22 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 } |
