public static Interpreter Create() { var repl_env = new Mal.env.Env(null); Func <string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } repl_env.set(new MalSymbol("eval"), new MalFunc( a => EVAL(a[0], repl_env))); // core.mal: defined using the language itself 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("(def! *gensym-counter* (atom 0))"); RE("(def! gensym (fn* [] (symbol (str \"G__\" (swap! *gensym-counter* (fn* [x] (+ 1 x)))))))"); RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); // repl loop RE("(println (str \"Mal [\" *host-language* \"]\"))"); return(new Interpreter(repl_env)); }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func <string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } // core.mal: defined using the language itself 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("user> "); if (line == null) { break; } if (line == "") { continue; } } catch (IOException e) { Console.WriteLine("IOException: " + e.Message); break; } try { Console.WriteLine(PRINT(RE(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl 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 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; } // repl loop while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func <string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } repl_env.set(new MalSymbol("eval"), new MalFunc( a => EVAL(a[0], repl_env))); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; fileIdx = 1; } MalList _argv = new MalList(); for (int i = fileIdx + 1; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set(new MalSymbol("*ARGV*"), _argv); // core.mal: defined using the language itself 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))))))))"); if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; } // repl loop while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Mal.types.MalException e) { Console.WriteLine("Error: " + printer._pr_str(e.getValue(), false)); continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func <string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } repl_env.set(new MalSymbol("eval"), new MalFunc( a => EVAL(a[0], repl_env))); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; fileIdx = 1; } MalList _argv = new MalList(); for (int i = fileIdx + 1; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set(new MalSymbol("*ARGV*"), _argv); // core.mal: defined using the language itself RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; } // repl loop while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl 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 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; } // repl loop while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func<string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } repl_env.set(new MalSymbol("eval"), new MalFunc( a => EVAL(a[0], repl_env))); int fileIdx = 1; if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; fileIdx = 2; } MalList _argv = new MalList(); for (int i=fileIdx; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set(new MalSymbol("*ARGV*"), _argv); // core.mal: defined using the language itself RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; } // repl loop while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func<string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } repl_env.set(new MalSymbol("eval"), new MalFunc( a => EVAL(a[0], repl_env))); int fileIdx = 0; if (args.Length > 0 && args[0] == "--raw") { Mal.readline.mode = Mal.readline.Mode.Raw; fileIdx = 1; } MalList _argv = new MalList(); for (int i=fileIdx+1; i < args.Length; i++) { _argv.conj_BANG(new MalString(args[i])); } repl_env.set(new MalSymbol("*ARGV*"), _argv); // core.mal: defined using the language itself 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("(def! *gensym-counter* (atom 0))"); RE("(def! gensym (fn* [] (symbol (str \"G__\" (swap! *gensym-counter* (fn* [x] (+ 1 x)))))))"); RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); return; } // repl loop RE("(println (str \"Mal [\" *host-language* \"]\"))"); while (true) { string line; try { 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(line))); } catch (Mal.types.MalContinue) { continue; } catch (Mal.types.MalException e) { Console.WriteLine("Error: " + printer._pr_str(e.getValue(), false)); continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }
// repl static void Main(string[] args) { var repl_env = new Mal.env.Env(null); Func<string, MalVal> RE = (string str) => EVAL(READ(str), repl_env); // core.cs: defined using C# foreach (var entry in core.ns) { repl_env.set(new MalSymbol(entry.Key), entry.Value); } // core.mal: defined using the language itself 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("user> "); if (line == null) { break; } if (line == "") { continue; } } catch (IOException e) { Console.WriteLine("IOException: " + e.Message); break; } try { Console.WriteLine(PRINT(RE(line))); } catch (Mal.types.MalContinue) { continue; } catch (Exception e) { Console.WriteLine("Error: " + e.Message); Console.WriteLine(e.StackTrace); continue; } } }