diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-09 21:57:50 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-09 21:57:50 -0500 |
| commit | 17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837 (patch) | |
| tree | 878484c58d55c138e9553a1bde0d031772c8bbdb /cs/core.cs | |
| parent | faee4d12309cec8c90854456fabf4e5e75370518 (diff) | |
| download | mal-17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837.tar.gz mal-17ae845ec1dc2c703f99d3cb9f5c01e1b5c52837.zip | |
C#: add metadata and atoms.
Diffstat (limited to 'cs/core.cs')
| -rw-r--r-- | cs/core.cs | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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}, }; } } |
