From b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 18 Dec 2014 20:33:49 -0600 Subject: All: add keywords. Also, fix nth and count to match cloure. --- cs/step3_env.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'cs/step3_env.cs') diff --git a/cs/step3_env.cs b/cs/step3_env.cs index 9977811..6c4f2fe 100644 --- a/cs/step3_env.cs +++ b/cs/step3_env.cs @@ -22,8 +22,7 @@ namespace Mal { // eval static MalVal eval_ast(MalVal ast, Env env) { if (ast is MalSymbol) { - MalSymbol sym = (MalSymbol)ast; - return env.get(sym.getName()); + return env.get((MalSymbol)ast); } else if (ast is MalList) { MalList old_lst = (MalList)ast; MalList new_lst = ast.list_Q() ? new MalList() @@ -47,7 +46,7 @@ namespace Mal { static MalVal EVAL(MalVal orig_ast, Env env) { MalVal a0, a1, a2, res; MalList el; - //System.out.println("EVAL: " + printer._pr_str(orig_ast, true)); + //Console.WriteLine("EVAL: " + printer._pr_str(orig_ast, true)); if (!orig_ast.list_Q()) { return eval_ast(orig_ast, env); } @@ -66,7 +65,7 @@ namespace Mal { a1 = ast[1]; a2 = ast[2]; res = EVAL(a2, env); - env.set(((MalSymbol)a1).getName(), res); + env.set((MalSymbol)a1, res); return res; case "let*": a1 = ast[1]; @@ -77,7 +76,7 @@ namespace Mal { for(int i=0; i<((MalList)a1).size(); i+=2) { key = (MalSymbol)((MalList)a1)[i]; val = ((MalList)a1)[i+1]; - let_env.set(key.getName(), EVAL(val, let_env)); + let_env.set(key, EVAL(val, let_env)); } return EVAL(a2, let_env); default: @@ -96,10 +95,14 @@ namespace Mal { static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func RE = (string str) => EVAL(READ(str), repl_env); - repl_env.set("+", new MalFunc(a => (MalInt)a[0] + (MalInt)a[1]) ); - repl_env.set("-", new MalFunc(a => (MalInt)a[0] - (MalInt)a[1]) ); - repl_env.set("*", new MalFunc(a => (MalInt)a[0] * (MalInt)a[1]) ); - repl_env.set("/", new MalFunc(a => (MalInt)a[0] / (MalInt)a[1]) ); + repl_env.set(new MalSymbol("+"), new MalFunc( + a => (MalInt)a[0] + (MalInt)a[1]) ); + repl_env.set(new MalSymbol("-"), new MalFunc( + a => (MalInt)a[0] - (MalInt)a[1]) ); + repl_env.set(new MalSymbol("*"), new MalFunc( + a => (MalInt)a[0] * (MalInt)a[1]) ); + repl_env.set(new MalSymbol("/"), new MalFunc( + a => (MalInt)a[0] / (MalInt)a[1]) ); if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; -- cgit v1.2.3