aboutsummaryrefslogtreecommitdiff
path: root/cs/step3_env.cs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-07 00:17:13 -0500
committerJoel Martin <github@martintribe.org>2014-04-07 00:17:13 -0500
commitafdf531eba459a7a7b6505b037dbe48a363c2c79 (patch)
treeb899e21b373ac8338756140eaf7afcb399d46bb9 /cs/step3_env.cs
parentb18969c0b8d47d67d4b73b5b20742a0bc3179e72 (diff)
downloadmal-afdf531eba459a7a7b6505b037dbe48a363c2c79.tar.gz
mal-afdf531eba459a7a7b6505b037dbe48a363c2c79.zip
CS: add step4_if_fn_do
Diffstat (limited to 'cs/step3_env.cs')
-rw-r--r--cs/step3_env.cs23
1 files changed, 17 insertions, 6 deletions
diff --git a/cs/step3_env.cs b/cs/step3_env.cs
index 0fbbda7..032fadd 100644
--- a/cs/step3_env.cs
+++ b/cs/step3_env.cs
@@ -13,7 +13,7 @@ using MalFunction = Mal.types.MalFunction;
using Env = Mal.env.Env;
namespace Mal {
- class step1_repl {
+ class step3_env {
// read
static MalVal READ(string str) {
return reader.read_str(str);
@@ -46,6 +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));
if (!orig_ast.list_Q()) {
return eval_ast(orig_ast, env);
@@ -80,7 +81,7 @@ namespace Mal {
}
return EVAL(a2, let_env);
default:
- var el = (MalList)eval_ast(ast, env);
+ el = (MalList)eval_ast(ast, env);
var f = (MalFunction)el.nth(0);
return f.apply(el.rest());
}
@@ -99,14 +100,24 @@ namespace Mal {
return env.set(name, mv);
}
+ 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);
- _ref(repl_env, "+", new Mal.core.plus() );
- _ref(repl_env, "-", new Mal.core.minus() );
- _ref(repl_env, "*", new Mal.core.multiply() );
- _ref(repl_env, "/", new Mal.core.divide() );
+ _ref(repl_env, "+", plus);
+ _ref(repl_env, "-", minus);
+ _ref(repl_env, "*", multiply);
+ _ref(repl_env, "/", divide);
if (args.Length > 0 && args[0] == "--raw") {
Mal.readline.mode = Mal.readline.Mode.Raw;