From faee4d12309cec8c90854456fabf4e5e75370518 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 9 Apr 2014 21:26:35 -0500 Subject: C#: add stepA_more and core functions. --- cs/types.cs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'cs/types.cs') 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(); - assoc_BANG(lst.getValue().ToArray()); - } - /* - public MalHashMap(params MalVal[] mvs) { - value = new Dictionary(); - assoc_BANG(mvs); + assoc_BANG(lst); } - */ public MalHashMap copy() { - return (MalHashMap)this.MemberwiseClone(); + var new_self = (MalHashMap)this.MemberwiseClone(); + new_self.value = new Dictionary(value); + return new_self; } public Dictionary 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