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 | |
| parent | 95ec2d81d8661e56b7b98a1c19ad503c5083c1e4 (diff) | |
| download | mal-c3b508af92800f63bf99f41af68f026535f454f5.tar.gz mal-c3b508af92800f63bf99f41af68f026535f454f5.zip | |
C#: use closure for RE func. Shorter type names.
| -rw-r--r-- | cs/core.cs | 121 | ||||
| -rw-r--r-- | cs/reader.cs | 2 | ||||
| -rw-r--r-- | cs/step1_read_print.cs | 15 | ||||
| -rw-r--r-- | cs/step2_eval.cs | 37 | ||||
| -rw-r--r-- | cs/step3_env.cs | 38 | ||||
| -rw-r--r-- | cs/step4_if_fn_do.cs | 25 | ||||
| -rw-r--r-- | cs/step5_tco.cs | 25 | ||||
| -rw-r--r-- | cs/step6_file.cs | 31 | ||||
| -rw-r--r-- | cs/step7_quote.cs | 31 | ||||
| -rw-r--r-- | cs/step8_macros.cs | 43 | ||||
| -rw-r--r-- | cs/step9_try.cs | 47 | ||||
| -rw-r--r-- | cs/stepA_interop.cs | 47 | ||||
| -rw-r--r-- | cs/types.cs | 43 |
13 files changed, 230 insertions, 275 deletions
@@ -3,14 +3,14 @@ using System.IO; using System.Collections.Generic; using MalVal = Mal.types.MalVal; using MalConstant = Mal.types.MalConstant; -using MalInteger = Mal.types.MalInteger; +using MalInt = Mal.types.MalInt; using MalSymbol = Mal.types.MalSymbol; using MalString = Mal.types.MalString; using MalList = Mal.types.MalList; using MalVector = Mal.types.MalVector; using MalHashMap = Mal.types.MalHashMap; using MalAtom = Mal.types.MalAtom; -using MalFunction = Mal.types.MalFunction; +using MalFunc = Mal.types.MalFunc; namespace Mal { public class core { @@ -19,93 +19,93 @@ namespace Mal { static MalConstant False = Mal.types.False; // Errors/Exceptions - static public MalFunction mal_throw = new MalFunction( + static public MalFunc mal_throw = new MalFunc( a => { throw new Mal.types.MalException(a[0]); }); // Scalar functions - static MalFunction nil_Q = new MalFunction( + static MalFunc nil_Q = new MalFunc( a => a[0] == Nil ? True : False); - static MalFunction true_Q = new MalFunction( + static MalFunc true_Q = new MalFunc( a => a[0] == True ? True : False); - static MalFunction false_Q = new MalFunction( + static MalFunc false_Q = new MalFunc( a => a[0] == False ? True : False); - static MalFunction symbol_Q = new MalFunction( + static MalFunc symbol_Q = new MalFunc( a => a[0] is MalSymbol ? True : False); // Number functions - static MalFunction time_ms = new MalFunction( - a => new MalInteger((int)( + static MalFunc time_ms = new MalFunc( + a => new MalInt((int)( DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond))); // String functions - static public MalFunction pr_str = new MalFunction( + static public MalFunc pr_str = new MalFunc( a => new MalString(printer._pr_str_args(a, " ", true)) ); - static public MalFunction str = new MalFunction( + static public MalFunc str = new MalFunc( a => new MalString(printer._pr_str_args(a, "", false)) ); - static public MalFunction prn = new MalFunction( + static public MalFunc prn = new MalFunc( a => { Console.WriteLine(printer._pr_str_args(a, " ", true)); return Nil; } ); - static public MalFunction println = new MalFunction( + static public MalFunc println = new MalFunc( a => { Console.WriteLine(printer._pr_str_args(a, " ", false)); return Nil; } ); - static public MalFunction mal_readline = new MalFunction( + static public MalFunc mal_readline = new MalFunc( a => { var line = readline.Readline(((MalString)a[0]).getValue()); if (line == null) { return types.Nil; } else { return new MalString(line); } } ); - static public MalFunction read_string = new MalFunction( + static public MalFunc read_string = new MalFunc( a => reader.read_str(((MalString)a[0]).getValue())); - static public MalFunction slurp = new MalFunction( + static public MalFunc slurp = new MalFunc( a => new MalString(File.ReadAllText( ((MalString)a[0]).getValue()))); // List/Vector functions - static public MalFunction list_Q = new MalFunction( + static public MalFunc list_Q = new MalFunc( a => a[0].GetType() == typeof(MalList) ? True : False); - static public MalFunction vector_Q = new MalFunction( + static public MalFunc vector_Q = new MalFunc( a => a[0].GetType() == typeof(MalVector) ? True : False); // HashMap functions - static public MalFunction hash_map_Q = new MalFunction( + static public MalFunc hash_map_Q = new MalFunc( a => a[0].GetType() == typeof(MalHashMap) ? True : False); - static MalFunction contains_Q = new MalFunction( + static MalFunc contains_Q = new MalFunc( a => { string key = ((MalString)a[1]).getValue(); var dict = ((MalHashMap)a[0]).getValue(); return dict.ContainsKey(key) ? True : False; }); - static MalFunction assoc = new MalFunction( + static MalFunc assoc = new MalFunc( a => { var new_hm = ((MalHashMap)a[0]).copy(); return new_hm.assoc_BANG((MalList)a.slice(1)); }); - static MalFunction dissoc = new MalFunction( + static MalFunc dissoc = new MalFunc( a => { var new_hm = ((MalHashMap)a[0]).copy(); return new_hm.dissoc_BANG((MalList)a.slice(1)); }); - static MalFunction get = new MalFunction( + static MalFunc get = new MalFunc( a => { string key = ((MalString)a[1]).getValue(); if (a[0] == Nil) { @@ -116,7 +116,7 @@ namespace Mal { } }); - static MalFunction keys = new MalFunction( + static MalFunc keys = new MalFunc( a => { var dict = ((MalHashMap)a[0]).getValue(); MalList key_lst = new MalList(); @@ -126,7 +126,7 @@ namespace Mal { return key_lst; }); - static MalFunction vals = new MalFunction( + static MalFunc vals = new MalFunc( a => { var dict = ((MalHashMap)a[0]).getValue(); MalList val_lst = new MalList(); @@ -137,10 +137,10 @@ namespace Mal { }); // Sequence functions - static public MalFunction sequential_Q = new MalFunction( + static public MalFunc sequential_Q = new MalFunc( a => a[0] is MalList ? True : False); - static MalFunction cons = new MalFunction( + static MalFunc cons = new MalFunc( a => { var lst = new List<MalVal>(); lst.Add(a[0]); @@ -148,7 +148,7 @@ namespace Mal { return (MalVal)new MalList(lst); }); - static MalFunction concat = new MalFunction( + static MalFunc concat = new MalFunc( a => { if (a.size() == 0) { return new MalList(); } var lst = new List<MalVal>(); @@ -159,22 +159,22 @@ namespace Mal { return (MalVal)new MalList(lst); }); - static MalFunction nth = new MalFunction( - a => ((MalList)a[0])[ ((MalInteger)a[1]).getValue() ]); + static MalFunc nth = new MalFunc( + a => ((MalList)a[0])[ ((MalInt)a[1]).getValue() ]); - static MalFunction first = new MalFunction( + static MalFunc first = new MalFunc( a => ((MalList)a[0])[0]); - static MalFunction rest = new MalFunction( + static MalFunc rest = new MalFunc( a => ((MalList)a[0]).rest()); - static MalFunction empty_Q = new MalFunction( + static MalFunc empty_Q = new MalFunc( a => ((MalList)a[0]).size() == 0 ? True : False); - static MalFunction count = new MalFunction( - a => new MalInteger(((MalList)a[0]).size())); + static MalFunc count = new MalFunc( + a => new MalInt(((MalList)a[0]).size())); - static MalFunction conj = new MalFunction( + static MalFunc conj = new MalFunc( a => { var src_lst = ((MalList)a[0]).getValue(); var new_lst = new List<MalVal>(); @@ -194,18 +194,18 @@ namespace Mal { // General list related functions - static MalFunction apply = new MalFunction( + static MalFunc apply = new MalFunc( a => { - var f = (MalFunction)a[0]; + var f = (MalFunc)a[0]; var lst = new List<MalVal>(); lst.AddRange(a.slice(1,a.size()-1).getValue()); lst.AddRange(((MalList)a[a.size()-1]).getValue()); return f.apply(new MalList(lst)); }); - static MalFunction map = new MalFunction( + static MalFunc map = new MalFunc( a => { - MalFunction f = (MalFunction) a[0]; + MalFunc f = (MalFunc) a[0]; var src_lst = ((MalList)a[1]).getValue(); var new_lst = new List<MalVal>(); for(int i=0; i<src_lst.Count; i++) { @@ -216,27 +216,27 @@ namespace Mal { // Metadata functions - static MalFunction meta = new MalFunction( + static MalFunc meta = new MalFunc( a => a[0].getMeta()); - static MalFunction with_meta = new MalFunction( + static MalFunc with_meta = new MalFunc( a => ((MalVal)a[0]).copy().setMeta(a[1])); // Atom functions - static MalFunction atom_Q = new MalFunction( + static MalFunc atom_Q = new MalFunc( a => a[0] is MalAtom ? True : False); - static MalFunction deref = new MalFunction( + static MalFunc deref = new MalFunc( a => ((MalAtom)a[0]).getValue()); - static MalFunction reset_BANG = new MalFunction( + static MalFunc reset_BANG = new MalFunc( a => ((MalAtom)a[0]).setValue(a[1])); - static MalFunction swap_BANG = new MalFunction( + static MalFunc swap_BANG = new MalFunc( a => { MalAtom atm = (MalAtom)a[0]; - MalFunction f = (MalFunction)a[1]; + MalFunc f = (MalFunc)a[1]; var new_lst = new List<MalVal>(); new_lst.Add(atm.getValue()); new_lst.AddRange(((MalList)a.slice(2)).getValue()); @@ -247,12 +247,13 @@ namespace Mal { static public Dictionary<string, MalVal> ns = new Dictionary<string, MalVal> { - {"=", new MalFunction( + {"=", new MalFunc( a => Mal.types._equal_Q(a[0], a[1]) ? True : False)}, {"throw", mal_throw}, {"nil?", nil_Q}, {"true?", true_Q}, {"false?", false_Q}, + {"symbol", new MalFunc(a => new MalSymbol((MalString)a[0]))}, {"symbol?", symbol_Q}, {"pr-str", pr_str}, @@ -262,21 +263,21 @@ namespace Mal { {"readline", mal_readline}, {"read-string", read_string}, {"slurp", slurp}, - {"<", new MalFunction(a => (MalInteger)a[0] < (MalInteger)a[1])}, - {"<=", new MalFunction(a => (MalInteger)a[0] <= (MalInteger)a[1])}, - {">", new MalFunction(a => (MalInteger)a[0] > (MalInteger)a[1])}, - {">=", new MalFunction(a => (MalInteger)a[0] >= (MalInteger)a[1])}, - {"+", new MalFunction(a => (MalInteger)a[0] + (MalInteger)a[1])}, - {"-", new MalFunction(a => (MalInteger)a[0] - (MalInteger)a[1])}, - {"*", new MalFunction(a => (MalInteger)a[0] * (MalInteger)a[1])}, - {"/", new MalFunction(a => (MalInteger)a[0] / (MalInteger)a[1])}, + {"<", new MalFunc(a => (MalInt)a[0] < (MalInt)a[1])}, + {"<=", new MalFunc(a => (MalInt)a[0] <= (MalInt)a[1])}, + {">", new MalFunc(a => (MalInt)a[0] > (MalInt)a[1])}, + {">=", new MalFunc(a => (MalInt)a[0] >= (MalInt)a[1])}, + {"+", new MalFunc(a => (MalInt)a[0] + (MalInt)a[1])}, + {"-", new MalFunc(a => (MalInt)a[0] - (MalInt)a[1])}, + {"*", new MalFunc(a => (MalInt)a[0] * (MalInt)a[1])}, + {"/", new MalFunc(a => (MalInt)a[0] / (MalInt)a[1])}, {"time-ms", time_ms}, - {"list", new MalFunction(a => new MalList(a.getValue()))}, + {"list", new MalFunc(a => new MalList(a.getValue()))}, {"list?", list_Q}, - {"vector", new MalFunction(a => new MalVector(a.getValue()))}, + {"vector", new MalFunc(a => new MalVector(a.getValue()))}, {"vector?", vector_Q}, - {"hash-map", new MalFunction(a => new MalHashMap(a))}, + {"hash-map", new MalFunc(a => new MalHashMap(a))}, {"map?", hash_map_Q}, {"contains?", contains_Q}, {"assoc", assoc}, @@ -299,7 +300,7 @@ namespace Mal { {"with-meta", with_meta}, {"meta", meta}, - {"atom", new MalFunction(a => new MalAtom(a[0]))}, + {"atom", new MalFunc(a => new MalAtom(a[0]))}, {"atom?", atom_Q}, {"deref", deref}, {"reset!", reset_BANG}, diff --git a/cs/reader.cs b/cs/reader.cs index 8ab53da..dbc74af 100644 --- a/cs/reader.cs +++ b/cs/reader.cs @@ -61,7 +61,7 @@ namespace Mal { throw new ParseError("unrecognized token '" + token + "'"); } if (match.Groups[1].Value != String.Empty) { - return new Mal.types.MalInteger(int.Parse(match.Groups[1].Value)); + return new Mal.types.MalInt(int.Parse(match.Groups[1].Value)); } else if (match.Groups[3].Value != String.Empty) { return Mal.types.Nil; } else if (match.Groups[4].Value != String.Empty) { diff --git a/cs/step1_read_print.cs b/cs/step1_read_print.cs index 1b427c8..43bf3c4 100644 --- a/cs/step1_read_print.cs +++ b/cs/step1_read_print.cs @@ -21,27 +21,26 @@ namespace Mal { } // repl - static MalVal RE(string env, string str) { - return EVAL(READ(str), env); - } - static void Main(string[] args) { - string prompt = "user> "; - + Func<string, MalVal> RE = (string str) => EVAL(READ(str), ""); + if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } + + // 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(null, line))); + Console.WriteLine(PRINT(RE(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { diff --git a/cs/step2_eval.cs b/cs/step2_eval.cs index 1a95a81..0c7db69 100644 --- a/cs/step2_eval.cs +++ b/cs/step2_eval.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using Mal; using MalVal = Mal.types.MalVal; 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; namespace Mal { class step1_eval { @@ -59,7 +59,7 @@ namespace Mal { + Mal.printer._pr_str(a0,true) + "'"); } var el = (MalList)eval_ast(ast, env); - var f = (MalFunction)el[0]; + var f = (MalFunc)el[0]; return f.apply(el.rest()); } @@ -70,43 +70,32 @@ namespace Mal { } // repl - static MalVal RE(Dictionary<string, MalVal> env, string str) { - return EVAL(READ(str), env); - } - - static public MalFunction plus = new MalFunction( - a => (MalInteger)a[0] + (MalInteger)a[1] ); - static public MalFunction minus = new MalFunction( - a => (MalInteger)a[0] - (MalInteger)a[1] ); - static public MalFunction multiply = new MalFunction( - a => (MalInteger)a[0] * (MalInteger)a[1] ); - static public MalFunction divide = new MalFunction( - a => (MalInteger)a[0] / (MalInteger)a[1] ); - static void Main(string[] args) { - string prompt = "user> "; - var repl_env = new Dictionary<string, MalVal> { - {"+", plus}, - {"-", minus}, - {"*", multiply}, - {"/", divide}, + {"+", new MalFunc(a => (MalInt)a[0] + (MalInt)a[1]) }, + {"-", new MalFunc(a => (MalInt)a[0] - (MalInt)a[1]) }, + {"*", new MalFunc(a => (MalInt)a[0] * (MalInt)a[1]) }, + {"/", new MalFunc(a => (MalInt)a[0] / (MalInt)a[1]) }, }; + Func<string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } + + // 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) { diff --git a/cs/step3_env.cs b/cs/step3_env.cs index 2be7992..9977811 100644 --- a/cs/step3_env.cs +++ b/cs/step3_env.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using Mal; using MalVal = Mal.types.MalVal; 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 { @@ -82,7 +82,7 @@ namespace Mal { return EVAL(a2, let_env); default: el = (MalList)eval_ast(ast, env); - var f = (MalFunction)el[0]; + var f = (MalFunc)el[0]; return f.apply(el.rest()); } } @@ -93,45 +93,31 @@ namespace Mal { } // repl - static MalVal RE(Env env, string str) { - return EVAL(READ(str), env); - } - - static public MalFunction plus = new MalFunction( - a => (MalInteger)a[0] + (MalInteger)a[1] ); - static public MalFunction minus = new MalFunction( - a => (MalInteger)a[0] - (MalInteger)a[1] ); - static public MalFunction multiply = new MalFunction( - a => (MalInteger)a[0] * (MalInteger)a[1] ); - static public MalFunction divide = new MalFunction( - a => (MalInteger)a[0] / (MalInteger)a[1] ); - - static void Main(string[] args) { - string prompt = "user> "; - var repl_env = new Mal.env.Env(null); - repl_env.set("+", plus); - repl_env.set("-", minus); - repl_env.set("*", multiply); - repl_env.set("/", divide); + 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]) ); if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } - + // 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) { diff --git a/cs/step4_if_fn_do.cs b/cs/step4_if_fn_do.cs index 659fc18..ff8c3b9 100644 --- a/cs/step4_if_fn_do.cs +++ b/cs/step4_if_fn_do.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using Mal; using MalVal = Mal.types.MalVal; 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 { @@ -102,11 +102,11 @@ namespace Mal { MalList a1f = (MalList)ast[1]; MalVal a2f = ast[2]; Env cur_env = env; - return new MalFunction( + return new MalFunc( 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]; return f.apply(el.rest()); } } @@ -117,38 +117,35 @@ 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); } // core.mal: defined using the language itself - RE(repl_env, "(def! not (fn* (a) (if a false true)))"); + RE("(def! not (fn* (a) (if a false true)))"); if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } - + // 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) { diff --git a/cs/step5_tco.cs b/cs/step5_tco.cs index e243153..f1307f0 100644 --- a/cs/step5_tco.cs +++ b/cs/step5_tco.cs @@ -5,11 +5,11 @@ using System.Collections.Generic; using Mal; using MalVal = Mal.types.MalVal; 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 { @@ -107,11 +107,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; @@ -131,38 +131,35 @@ 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); } // core.mal: defined using the language itself - RE(repl_env, "(def! not (fn* (a) (if a false true)))"); + RE("(def! not (fn* (a) (if a false true)))"); if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; } - + // 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) { 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) { diff --git a/cs/step7_quote.cs b/cs/step7_quote.cs index 537c20c..7c4cf11 100644 --- a/cs/step7_quote.cs +++ b/cs/step7_quote.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 { @@ -140,11 +140,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; @@ -164,19 +164,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])); @@ -184,8 +180,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") { @@ -193,22 +189,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) { diff --git a/cs/step8_macros.cs b/cs/step8_macros.cs index b06b1fb..1aaa1fa 100644 --- a/cs/step8_macros.cs +++ b/cs/step8_macros.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 { @@ -54,8 +54,8 @@ namespace Mal { if (a0 is MalSymbol && env.find(((MalSymbol)a0).getName()) != null) { MalVal mac = env.get(((MalSymbol)a0).getName()); - if (mac is MalFunction && - ((MalFunction)mac).isMacro()) { + if (mac is MalFunc && + ((MalFunc)mac).isMacro()) { return true; } } @@ -66,7 +66,7 @@ namespace Mal { public static MalVal macroexpand(MalVal ast, Env env) { while (is_macro_call(ast, env)) { MalSymbol a0 = (MalSymbol)((MalList)ast)[0]; - MalFunction mac = (MalFunction) env.get(a0.getName()); + MalFunc mac = (MalFunc) env.get(a0.getName()); ast = mac.apply(((MalList)ast).rest()); } return ast; @@ -148,7 +148,7 @@ namespace Mal { a1 = ast[1]; a2 = ast[2]; res = EVAL(a2, env); - ((MalFunction)res).setMacro(); + ((MalFunc)res).setMacro(); env.set(((MalSymbol)a1).getName(), res); return res; case "macroexpand": @@ -177,11 +177,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; @@ -201,19 +201,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])); @@ -221,10 +217,10 @@ 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(repl_env, "(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)))))))"); - RE(repl_env, "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); + RE("(def! not (fn* (a) (if a false true)))"); + RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); + RE("(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)))))))"); + RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { @@ -232,22 +228,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) { diff --git a/cs/step9_try.cs b/cs/step9_try.cs index ed3417c..e5da607 100644 --- a/cs/step9_try.cs +++ b/cs/step9_try.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 { @@ -54,8 +54,8 @@ namespace Mal { if (a0 is MalSymbol && env.find(((MalSymbol)a0).getName()) != null) { MalVal mac = env.get(((MalSymbol)a0).getName()); - if (mac is MalFunction && - ((MalFunction)mac).isMacro()) { + if (mac is MalFunc && + ((MalFunc)mac).isMacro()) { return true; } } @@ -66,7 +66,7 @@ namespace Mal { public static MalVal macroexpand(MalVal ast, Env env) { while (is_macro_call(ast, env)) { MalSymbol a0 = (MalSymbol)((MalList)ast)[0]; - MalFunction mac = (MalFunction) env.get(a0.getName()); + MalFunc mac = (MalFunc) env.get(a0.getName()); ast = mac.apply(((MalList)ast).rest()); } return ast; @@ -148,7 +148,7 @@ namespace Mal { a1 = ast[1]; a2 = ast[2]; res = EVAL(a2, env); - ((MalFunction)res).setMacro(); + ((MalFunc)res).setMacro(); env.set(((MalSymbol)a1).getName(), res); return res; case "macroexpand": @@ -198,11 +198,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; @@ -222,19 +222,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])); @@ -242,11 +238,11 @@ namespace Mal { repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself - RE(repl_env, "(def! *host-language* \"c#\")"); - 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(repl_env, "(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)))))))"); - RE(repl_env, "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); + RE("(def! *host-language* \"c#\")"); + RE("(def! not (fn* (a) (if a false true)))"); + RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); + RE("(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)))))))"); + RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { @@ -254,23 +250,24 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - RE(repl_env, "(load-file \"" + args[fileIdx] + "\")"); + RE("(load-file \"" + args[fileIdx] + "\")"); return; } - + // repl loop - RE(repl_env, "(println (str \"Mal [\" *host-language* \"]\"))"); + RE("(println (str \"Mal [\" *host-language* \"]\"))"); 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 (Mal.types.MalException e) { diff --git a/cs/stepA_interop.cs b/cs/stepA_interop.cs index 632d18d..d84eca2 100644 --- a/cs/stepA_interop.cs +++ b/cs/stepA_interop.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 { @@ -54,8 +54,8 @@ namespace Mal { if (a0 is MalSymbol && env.find(((MalSymbol)a0).getName()) != null) { MalVal mac = env.get(((MalSymbol)a0).getName()); - if (mac is MalFunction && - ((MalFunction)mac).isMacro()) { + if (mac is MalFunc && + ((MalFunc)mac).isMacro()) { return true; } } @@ -66,7 +66,7 @@ namespace Mal { public static MalVal macroexpand(MalVal ast, Env env) { while (is_macro_call(ast, env)) { MalSymbol a0 = (MalSymbol)((MalList)ast)[0]; - MalFunction mac = (MalFunction) env.get(a0.getName()); + MalFunc mac = (MalFunc) env.get(a0.getName()); ast = mac.apply(((MalList)ast).rest()); } return ast; @@ -148,7 +148,7 @@ namespace Mal { a1 = ast[1]; a2 = ast[2]; res = EVAL(a2, env); - ((MalFunction)res).setMacro(); + ((MalFunc)res).setMacro(); env.set(((MalSymbol)a1).getName(), res); return res; case "macroexpand": @@ -198,11 +198,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; @@ -222,19 +222,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])); @@ -242,11 +238,11 @@ namespace Mal { repl_env.set("*ARGV*", _argv); // core.mal: defined using the language itself - RE(repl_env, "(def! *host-language* \"c#\")"); - 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(repl_env, "(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)))))))"); - RE(repl_env, "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); + RE("(def! *host-language* \"c#\")"); + RE("(def! not (fn* (a) (if a false true)))"); + RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); + RE("(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)))))))"); + RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))"); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { @@ -254,23 +250,24 @@ namespace Mal { fileIdx = 1; } if (args.Length > fileIdx) { - RE(repl_env, "(load-file \"" + args[fileIdx] + "\")"); + RE("(load-file \"" + args[fileIdx] + "\")"); return; } - + // repl loop - RE(repl_env, "(println (str \"Mal [\" *host-language* \"]\"))"); + RE("(println (str \"Mal [\" *host-language* \"]\"))"); 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 (Mal.types.MalException e) { diff --git a/cs/types.cs b/cs/types.cs index b49adb6..fd0b9fb 100644 --- a/cs/types.cs +++ b/cs/types.cs @@ -39,9 +39,9 @@ namespace Mal { (a is MalList && b is MalList))) { return false; } else { - if (a is MalInteger) { - return ((MalInteger)a).getValue() == - ((MalInteger)b).getValue(); + if (a is MalInt) { + return ((MalInt)a).getValue() == + ((MalInt)b).getValue(); } else if (a is MalSymbol) { return ((MalSymbol)a).getName() == ((MalSymbol)b).getName(); @@ -97,10 +97,10 @@ namespace Mal { static public MalConstant True = new MalConstant("true"); static public MalConstant False = new MalConstant("false"); - public class MalInteger : MalVal { + public class MalInt : MalVal { int value; - public MalInteger(int v) { value = v; } - public new MalInteger copy() { return this; } + public MalInt(int v) { value = v; } + public new MalInt copy() { return this; } public int getValue() { return value; } public override string ToString() { @@ -109,35 +109,36 @@ namespace Mal { public override string ToString(bool print_readably) { return value.ToString(); } - public static MalConstant operator <(MalInteger a, MalInteger b) { + public static MalConstant operator <(MalInt a, MalInt b) { return a.getValue() < b.getValue() ? True : False; } - public static MalConstant operator <=(MalInteger a, MalInteger b) { + public static MalConstant operator <=(MalInt a, MalInt b) { return a.getValue() <= b.getValue() ? True : False; } - public static MalConstant operator >(MalInteger a, MalInteger b) { + public static MalConstant operator >(MalInt a, MalInt b) { return a.getValue() > b.getValue() ? True : False; } - public static MalConstant operator >=(MalInteger a, MalInteger b) { + public static MalConstant operator >=(MalInt a, MalInt b) { return a.getValue() >= b.getValue() ? True : False; } - public static MalInteger operator +(MalInteger a, MalInteger b) { - return new MalInteger(a.getValue() + b.getValue()); + public static MalInt operator +(MalInt a, MalInt b) { + return new MalInt(a.getValue() + b.getValue()); } - public static MalInteger operator -(MalInteger a, MalInteger b) { - return new MalInteger(a.getValue() - b.getValue()); + public static MalInt operator -(MalInt a, MalInt b) { + return new MalInt(a.getValue() - b.getValue()); } - public static MalInteger operator *(MalInteger a, MalInteger b) { - return new MalInteger(a.getValue() * b.getValue()); + public static MalInt operator *(MalInt a, MalInt b) { + return new MalInt(a.getValue() * b.getValue()); } - public static MalInteger operator /(MalInteger a, MalInteger b) { - return new MalInteger(a.getValue() / b.getValue()); + public static MalInt operator /(MalInt a, MalInt b) { + return new MalInt(a.getValue() / b.getValue()); } } public class MalSymbol : MalVal { string value; public MalSymbol(string v) { value = v; } + public MalSymbol(MalString v) { value = v.getValue(); } public new MalSymbol copy() { return this; } public string getName() { return value; } @@ -298,16 +299,16 @@ namespace Mal { } } - public class MalFunction : MalVal { + public class MalFunc : MalVal { Func<MalList, MalVal> fn = null; MalVal ast = null; Mal.env.Env env = null; MalList fparams; bool macro = false; - public MalFunction(Func<MalList, MalVal> fn) { + public MalFunc(Func<MalList, MalVal> fn) { this.fn = fn; } - public MalFunction(MalVal ast, Mal.env.Env env, MalList fparams, + public MalFunc(MalVal ast, Mal.env.Env env, MalList fparams, Func<MalList, MalVal> fn) { this.fn = fn; this.ast = ast; |
