aboutsummaryrefslogtreecommitdiff
path: root/go/src/step9_try
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /go/src/step9_try
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'go/src/step9_try')
-rw-r--r--go/src/step9_try/step9_try.go24
1 files changed, 11 insertions, 13 deletions
diff --git a/go/src/step9_try/step9_try.go b/go/src/step9_try/step9_try.go
index 322ee36..18f3c9c 100644
--- a/go/src/step9_try/step9_try.go
+++ b/go/src/step9_try/step9_try.go
@@ -55,8 +55,8 @@ func is_macro_call(ast MalType, env EnvType) bool {
if List_Q(ast) {
slc, _ := GetSlice(ast)
a0 := slc[0]
- if Symbol_Q(a0) && env.Find(a0.(Symbol).Val) != nil {
- mac, e := env.Get(a0.(Symbol).Val)
+ if Symbol_Q(a0) && env.Find(a0.(Symbol)) != nil {
+ mac, e := env.Get(a0.(Symbol))
if e != nil { return false }
if MalFunc_Q(mac) {
return mac.(MalFunc).GetMacro()
@@ -72,7 +72,7 @@ func macroexpand(ast MalType, env EnvType) (MalType, error) {
for ; is_macro_call(ast, env) ; {
slc, _ := GetSlice(ast)
a0 := slc[0]
- mac, e = env.Get(a0.(Symbol).Val); if e != nil { return nil, e }
+ mac, e = env.Get(a0.(Symbol)); if e != nil { return nil, e }
fn := mac.(MalFunc)
ast, e = Apply(fn, slc[1:]); if e != nil { return nil, e }
}
@@ -82,7 +82,7 @@ func macroexpand(ast MalType, env EnvType) (MalType, error) {
func eval_ast(ast MalType, env EnvType) (MalType, error) {
//fmt.Printf("eval_ast: %#v\n", ast)
if Symbol_Q(ast) {
- return env.Get(ast.(Symbol).Val)
+ return env.Get(ast.(Symbol))
} else if List_Q(ast) {
lst := []MalType{}
for _, a := range ast.(List).Val {
@@ -148,7 +148,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
case "def!":
res, e := EVAL(a2, env)
if e != nil { return nil, e }
- return env.Set(a1.(Symbol).Val, res), nil
+ return env.Set(a1.(Symbol), res), nil
case "let*":
let_env, e := NewEnv(env, nil, nil)
if e != nil { return nil, e }
@@ -160,7 +160,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
}
exp, e := EVAL(arr1[i+1], let_env)
if e != nil { return nil, e }
- let_env.Set(arr1[i].(Symbol).Val, exp)
+ let_env.Set(arr1[i].(Symbol), exp)
}
ast = a2
env = let_env
@@ -172,7 +172,7 @@ func EVAL(ast MalType, env EnvType) (MalType, error) {
fn, e := EVAL(a2, env)
fn = fn.(MalFunc).SetMacro()
if e != nil { return nil, e }
- return env.Set(a1.(Symbol).Val, fn), nil
+ return env.Set(a1.(Symbol), fn), nil
case "macroexpand":
return macroexpand(a1, env)
case "try*":
@@ -259,14 +259,13 @@ func rep(str string) (MalType, error) {
func main() {
// core.go: defined using go
for k, v := range core.NS {
- repl_env.Set(k, Func{v.(func([]MalType)(MalType,error)),nil})
+ repl_env.Set(Symbol{k}, Func{v.(func([]MalType)(MalType,error)),nil})
}
- repl_env.Set("eval", Func{func(a []MalType) (MalType, error) {
+ repl_env.Set(Symbol{"eval"}, Func{func(a []MalType) (MalType, error) {
return EVAL(a[0], repl_env) },nil})
- repl_env.Set("*ARGV*", List{})
+ repl_env.Set(Symbol{"*ARGV*"}, List{})
// core.mal: defined using the language itself
- rep("(def! *host-language* \"go\")")
rep("(def! not (fn* (a) (if a false true)))")
rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))")
rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))")
@@ -278,7 +277,7 @@ func main() {
for _,a := range os.Args[2:] {
args = append(args, a)
}
- repl_env.Set("*ARGV*", List{args,nil})
+ repl_env.Set(Symbol{"*ARGV*"}, List{args,nil})
if _,e := rep("(load-file \"" + os.Args[1] + "\")"); e != nil {
fmt.Printf("Error: %v\n", e)
os.Exit(1)
@@ -287,7 +286,6 @@ func main() {
}
// repl loop
- rep("(println (str \"Mal [\" *host-language* \"]\"))")
for {
text, err := readline.Readline("user> ")
text = strings.TrimRight(text, "\n");