diff options
| author | Joel Martin <github@martintribe.org> | 2014-04-09 21:26:35 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-04-09 21:26:35 -0500 |
| commit | faee4d12309cec8c90854456fabf4e5e75370518 (patch) | |
| tree | 25f9d4d74f958333976fe5c4bd9327ad86b77a09 /cs/types.cs | |
| parent | faa20db28295845973b895995c92a70a247f789c (diff) | |
| download | mal-faee4d12309cec8c90854456fabf4e5e75370518.tar.gz mal-faee4d12309cec8c90854456fabf4e5e75370518.zip | |
C#: add stepA_more and core functions.
Diffstat (limited to 'cs/types.cs')
| -rw-r--r-- | cs/types.cs | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/cs/types.cs b/cs/types.cs index cd94f94..642da7a 100644 --- a/cs/types.cs +++ b/cs/types.cs @@ -199,9 +199,11 @@ namespace Mal { } public int size() { return value.Count; } - public MalVal nth(int idx) { return value[idx]; } + public MalVal nth(int idx) { + return value.Count > 0 ? value[idx] : Nil; + } public MalVal this[int idx] { - get { return value[idx]; } + get { return value.Count > 0 ? value[idx] : Nil; } } public MalList rest() { if (size() > 0) { @@ -255,16 +257,12 @@ namespace Mal { } public MalHashMap(MalList lst) { value = new Dictionary<String, MalVal>(); - assoc_BANG(lst.getValue().ToArray()); - } - /* - public MalHashMap(params MalVal[] mvs) { - value = new Dictionary<String, MalVal>(); - assoc_BANG(mvs); + assoc_BANG(lst); } - */ public MalHashMap copy() { - return (MalHashMap)this.MemberwiseClone(); + var new_self = (MalHashMap)this.MemberwiseClone(); + new_self.value = new Dictionary<string, MalVal>(value); + return new_self; } public Dictionary<string, MalVal> getValue() { return value; } @@ -276,15 +274,16 @@ namespace Mal { return "{" + printer.join(value, " ", print_readably) + "}"; } - /* - public Set _entries() { - return value.entrySet(); + public MalHashMap assoc_BANG(MalList lst) { + for (int i=0; i<lst.size(); i+=2) { + value[((MalString)lst[i]).getValue()] = lst[i+1]; + } + return this; } - */ - - public MalHashMap assoc_BANG(params MalVal[] mvs) { - for (int i=0; i<mvs.Length; i+=2) { - value.Add(((MalString)mvs[i]).getValue(), mvs[i+1]); + + public MalHashMap dissoc_BANG(MalList lst) { + for (int i=0; i<lst.size(); i++) { + value.Remove(((MalString)lst[i]).getValue()); } return this; } @@ -306,6 +305,9 @@ namespace Mal { this.env = env; this.fparams = fparams; } + public MalFunction copy() { + return (MalFunction)this.MemberwiseClone(); + } public override string ToString() { if (ast != null) { |
