aboutsummaryrefslogtreecommitdiff
path: root/cs/step9_try.cs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /cs/step9_try.cs
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'cs/step9_try.cs')
-rw-r--r--cs/step9_try.cs24
1 files changed, 12 insertions, 12 deletions
diff --git a/cs/step9_try.cs b/cs/step9_try.cs
index 1d724d1..bea360c 100644
--- a/cs/step9_try.cs
+++ b/cs/step9_try.cs
@@ -52,8 +52,8 @@ namespace Mal {
if (ast is MalList) {
MalVal a0 = ((MalList)ast)[0];
if (a0 is MalSymbol &&
- env.find(((MalSymbol)a0).getName()) != null) {
- MalVal mac = env.get(((MalSymbol)a0).getName());
+ env.find((MalSymbol)a0) != null) {
+ MalVal mac = env.get((MalSymbol)a0);
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];
- MalFunc mac = (MalFunc) env.get(a0.getName());
+ MalFunc mac = (MalFunc) env.get(a0);
ast = mac.apply(((MalList)ast).rest());
}
return ast;
@@ -74,8 +74,7 @@ namespace Mal {
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()
@@ -102,7 +101,7 @@ namespace Mal {
while (true) {
- //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);
}
@@ -123,7 +122,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];
@@ -134,7 +133,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));
}
orig_ast = a2;
env = let_env;
@@ -149,7 +148,7 @@ namespace Mal {
a2 = ast[2];
res = EVAL(a2, env);
((MalFunc)res).setMacro();
- env.set(((MalSymbol)a1).getName(), res);
+ env.set(((MalSymbol)a1), res);
return res;
case "macroexpand":
a1 = ast[1];
@@ -228,9 +227,10 @@ namespace Mal {
// core.cs: defined using C#
foreach (var entry in core.ns) {
- repl_env.set(entry.Key, entry.Value);
+ repl_env.set(new MalSymbol(entry.Key), entry.Value);
}
- repl_env.set("eval", new MalFunc(a => EVAL(a[0], repl_env)));
+ 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;
@@ -240,7 +240,7 @@ namespace Mal {
for (int i=fileIdx; i < args.Length; i++) {
_argv.conj_BANG(new MalString(args[i]));
}
- repl_env.set("*ARGV*", _argv);
+ repl_env.set(new MalSymbol("*ARGV*"), _argv);
// core.mal: defined using the language itself
RE("(def! not (fn* (a) (if a false true)))");