diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-18 20:33:49 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:50 -0600 |
| commit | b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch) | |
| tree | f4d977ed220e9a3f665cfbf4f68770a81e4c2095 /cs/step3_env.cs | |
| parent | aaba249304b184e12e2445ab22d66df1f39a51a5 (diff) | |
| download | mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip | |
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'cs/step3_env.cs')
| -rw-r--r-- | cs/step3_env.cs | 21 |
1 files changed, 12 insertions, 9 deletions
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<string, MalVal> 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; |
