diff options
| author | Joel Martin <github@martintribe.org> | 2014-11-15 20:38:50 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:46 -0600 |
| commit | c3b508af92800f63bf99f41af68f026535f454f5 (patch) | |
| tree | e94c4f555375189c69cebada164afba80f2579bd /cs/step6_file.cs | |
| parent | 95ec2d81d8661e56b7b98a1c19ad503c5083c1e4 (diff) | |
| download | mal-c3b508af92800f63bf99f41af68f026535f454f5.tar.gz mal-c3b508af92800f63bf99f41af68f026535f454f5.zip | |
C#: use closure for RE func. Shorter type names.
Diffstat (limited to 'cs/step6_file.cs')
| -rw-r--r-- | cs/step6_file.cs | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/cs/step6_file.cs b/cs/step6_file.cs index 7e3bf7e..ab7a426 100644 --- a/cs/step6_file.cs +++ b/cs/step6_file.cs @@ -6,11 +6,11 @@ using Mal; using MalVal = Mal.types.MalVal; using MalString = Mal.types.MalString; using MalSymbol = Mal.types.MalSymbol; -using MalInteger = Mal.types.MalInteger; +using MalInt = Mal.types.MalInt; using MalList = Mal.types.MalList; using MalVector = Mal.types.MalVector; using MalHashMap = Mal.types.MalHashMap; -using MalFunction = Mal.types.MalFunction; +using MalFunc = Mal.types.MalFunc; using Env = Mal.env.Env; namespace Mal { @@ -108,11 +108,11 @@ namespace Mal { MalList a1f = (MalList)ast[1]; MalVal a2f = ast[2]; Env cur_env = env; - return new MalFunction(a2f, env, a1f, + return new MalFunc(a2f, env, a1f, args => EVAL(a2f, new Env(cur_env, a1f, args)) ); default: el = (MalList)eval_ast(ast, env); - var f = (MalFunction)el[0]; + var f = (MalFunc)el[0]; MalVal fnast = f.getAst(); if (fnast != null) { orig_ast = fnast; @@ -132,19 +132,15 @@ namespace Mal { } // repl - static MalVal RE(Env env, string str) { - return EVAL(READ(str), env); - } - static void Main(string[] args) { - string prompt = "user> "; + var repl_env = new Mal.env.Env(null); + Func<string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# - var repl_env = new env.Env(null); foreach (var entry in core.ns) { repl_env.set(entry.Key, entry.Value); } - repl_env.set("eval", new MalFunction(a => EVAL(a[0], repl_env))); + repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env))); MalList _argv = new MalList(); for (int i=1; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); @@ -152,8 +148,8 @@ namespace Mal { repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself - RE(repl_env, "(def! not (fn* (a) (if a false true)))"); - RE(repl_env, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); + RE("(def! not (fn* (a) (if a false true)))"); + RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { @@ -161,22 +157,23 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - RE(repl_env, "(load-file \"" + args[fileIdx] + "\")"); + RE("(load-file \"" + args[fileIdx] + "\")"); return; } - + // repl loop while (true) { string line; try { - line = Mal.readline.Readline(prompt); + line = Mal.readline.Readline("user> "); if (line == null) { break; } + if (line == "") { continue; } } catch (IOException e) { Console.WriteLine("IOException: " + e.Message); break; } try { - Console.WriteLine(PRINT(RE(repl_env, line))); + Console.WriteLine(PRINT(RE(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { |
