public void SingleConsTest() { var symbol = new Symbol("abc"); var cons = new Cons(symbol, LispNull.Nil); var enumerator = new ListEnumerator(cons); Assert.IsTrue(enumerator.MoveNext()); Assert.AreSame(symbol, enumerator.Current); Assert.IsFalse(enumerator.MoveNext()); }
public void AddBinding(Symbol symbol, LispObject value) { if (!dict.ContainsKey(symbol)) { dict.Add(symbol, value); } else { throw new EnvironmentException(symbol + " already bound"); } }
public bool TryLookUp(Symbol symbol, out LispObject value) { if (dict.TryGetValue(symbol, out value)) { return true; } if (!this.IsRoot) { return this.parent.TryLookUp(symbol, out value); } return false; }
public void SetValue(Symbol symbol, LispObject value) { if (dict.ContainsKey(symbol)) { dict[symbol] = value; } else if (!IsRoot) { parent.SetValue(symbol, value); } else { throw new EnvironmentException("No binding for " + symbol); } }
public LispObject LookUp(Symbol symbol) { LispObject result; if (!this.TryLookUp(symbol, out result)) { throw new EnvironmentException("No binding for " + symbol); } return result; }
private Symbol[] InternStars() { var name = string.Empty; var symbols = new Symbol[3]; for (int i = 0; i < symbols.Length; i++) { name += "*"; symbols[i] = environment.Symbols.Intern(name); } return symbols; }