aboutsummaryrefslogtreecommitdiff
path: root/go/src/step8_macros
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-09 21:37:00 -0500
committerJoel Martin <github@martintribe.org>2014-10-09 21:37:00 -0500
commitf2544a9467ea032aff505b3ced3b4b3510a828fe (patch)
treeaa1984aef01c20b7b093527c28c37bd7d4d803d5 /go/src/step8_macros
parentf2c9811fd8cbb205fad68952ebc1ba5d310f148d (diff)
downloadmal-f2544a9467ea032aff505b3ced3b4b3510a828fe.tar.gz
mal-f2544a9467ea032aff505b3ced3b4b3510a828fe.zip
go: add metadata and atoms. HashMap dedicated type.
HashMap needs a dedicated type now to be able to store the metadata.
Diffstat (limited to 'go/src/step8_macros')
-rw-r--r--go/src/step8_macros/step8_macros.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/go/src/step8_macros/step8_macros.go b/go/src/step8_macros/step8_macros.go
index 7a5c0e5..0feb739 100644
--- a/go/src/step8_macros/step8_macros.go
+++ b/go/src/step8_macros/step8_macros.go
@@ -30,7 +30,7 @@ func is_pair(x MalType) bool {
func quasiquote(ast MalType) MalType {
if !is_pair(ast) {
- return List{[]MalType{Symbol{"quote"}, ast}}
+ return List{[]MalType{Symbol{"quote"}, ast},nil}
} else {
slc, _ := GetSlice(ast)
a0 := slc[0]
@@ -42,12 +42,12 @@ func quasiquote(ast MalType) MalType {
if Symbol_Q(a00) && (a00.(Symbol).Val == "splice-unquote") {
return List{[]MalType{Symbol{"concat"},
slc0[1],
- quasiquote(List{slc[1:]})}}
+ quasiquote(List{slc[1:],nil})},nil}
}
}
return List{[]MalType{Symbol{"cons"},
quasiquote(a0),
- quasiquote(List{slc[1:]})}}
+ quasiquote(List{slc[1:],nil})},nil}
}
}
@@ -90,7 +90,7 @@ func eval_ast(ast MalType, env EnvType) (MalType, error) {
if e != nil { return nil, e }
lst = append(lst, exp)
}
- return List{lst}, nil
+ return List{lst,nil}, nil
} else if Vector_Q(ast) {
lst := []MalType{}
for _, a := range ast.(Vector).Val {
@@ -98,11 +98,11 @@ func eval_ast(ast MalType, env EnvType) (MalType, error) {
if e != nil { return nil, e }
lst = append(lst, exp)
}
- return Vector{lst}, nil
+ return Vector{lst,nil}, nil
} else if HashMap_Q(ast) {
- m := ast.(map[string]MalType)
- new_hm := map[string]MalType{}
- for k, v := range m {
+ m := ast.(HashMap)
+ new_hm := HashMap{map[string]MalType{},nil}
+ for k, v := range m.Val {
ke, e1 := EVAL(k, env)
if e1 != nil { return nil, e1 }
if _, ok := ke.(string); !ok {
@@ -110,7 +110,7 @@ func eval_ast(ast MalType, env EnvType) (MalType, error) {
}
kv, e2 := EVAL(v, env)
if e2 != nil { return nil, e2 }
- new_hm[ke.(string)] = kv
+ new_hm.Val[ke.(string)] = kv
}
return new_hm, nil
} else {
@@ -177,7 +177,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
return macroexpand(a1, env)
case "do":
lst := ast.(List).Val
- _, e := eval_ast(List{lst[1:len(lst)-1]}, env)
+ _, e := eval_ast(List{lst[1:len(lst)-1],nil}, env)
if e != nil { return nil, e }
if len(lst) == 1 { return nil, nil }
ast = lst[len(lst)-1]
@@ -194,7 +194,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
ast = a2
}
case "fn*":
- fn := MalFunc{EVAL, a2, env, a1, false, NewEnv}
+ fn := MalFunc{EVAL, a2, env, a1, false, NewEnv, nil}
return fn, nil
default:
el, e := eval_ast(ast, env)
@@ -203,7 +203,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
if MalFunc_Q(f) {
fn := f.(MalFunc)
ast = fn.Exp
- env, e = NewEnv(fn.Env, fn.Params, List{el.(List).Val[1:]})
+ env, e = NewEnv(fn.Env, fn.Params, List{el.(List).Val[1:],nil})
if e != nil { return nil, e }
} else {
fn, ok := f.(func([]MalType)(MalType, error))
@@ -253,7 +253,7 @@ func main() {
for _,a := range os.Args[2:] {
args = append(args, a)
}
- repl_env.Set("*ARGV*", List{args})
+ repl_env.Set("*ARGV*", List{args,nil})
rep("(load-file \"" + os.Args[1] + "\")")
os.Exit(0)
}