aboutsummaryrefslogtreecommitdiff
path: root/cs/core.cs
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-09 21:57:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-09 21:57:50 -0500
commit17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837 (patch)
tree878484c58d55c138e9553a1bde0d031772c8bbdb /cs/core.cs
parentfaee4d12309cec8c90854456fabf4e5e75370518 (diff)
downloadmal-17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837.tar.gz
mal-17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837.zip
C#: add metadata and atoms.
Diffstat (limited to 'cs/core.cs')
-rw-r--r--cs/core.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/cs/core.cs b/cs/core.cs
index f762075..f8bd7ff 100644
--- a/cs/core.cs
+++ b/cs/core.cs
@@ -8,6 +8,7 @@ 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;
namespace Mal {
@@ -189,6 +190,34 @@ namespace Mal {
});
+ // Metadata functions
+ static MalFunction meta = new MalFunction(
+ a => a[0].getMeta());
+
+ static MalFunction with_meta = new MalFunction(
+ a => ((MalVal)a[0]).copy().setMeta(a[1]));
+
+
+ // Atom functions
+ static MalFunction atom_Q = new MalFunction(
+ a => a[0] is MalAtom ? True : False);
+
+ static MalFunction deref = new MalFunction(
+ a => ((MalAtom)a[0]).getValue());
+
+ static MalFunction reset_BANG = new MalFunction(
+ a => ((MalAtom)a[0]).setValue(a[1]));
+
+ static MalFunction swap_BANG = new MalFunction(
+ a => {
+ MalAtom atm = (MalAtom)a[0];
+ MalFunction f = (MalFunction)a[1];
+ var new_lst = new List<MalVal>();
+ new_lst.Add(atm.getValue());
+ new_lst.AddRange(((MalList)a.slice(2)).getValue());
+ return atm.setValue(f.apply(new MalList(new_lst)));
+ });
+
static public Dictionary<string, MalVal> ns =
@@ -237,6 +266,14 @@ namespace Mal {
{"conj", conj},
{"apply", apply},
{"map", map},
+
+ {"with-meta", with_meta},
+ {"meta", meta},
+ {"atom", new MalFunction(a => new MalAtom(a[0]))},
+ {"atom?", atom_Q},
+ {"deref", deref},
+ {"reset!", reset_BANG},
+ {"swap!", swap_BANG},
};
}
}