public void MatchVariableInverse() { Context context = new Context(); Assert.IsTrue(MatchUtilities.MatchObjects(1, new Variable("X"), context)); Assert.AreEqual(1, context.GetValue("X")); }
public void MatchAnonymousVariable() { Context context = new Context(); Assert.IsTrue(MatchUtilities.MatchObjects(new Variable("_"), 1, context)); Assert.IsNull(context.GetValue("_")); }
public object Evaluate(Context context, bool withvars = false) { object left = this.leftexpr.Evaluate(context, true); object right = this.rightexpr.Evaluate(context, false); if (!MatchUtilities.MatchObjects(left, right, context)) { throw new InvalidOperationException(string.Format("no match of right hand side value {0}", right.ToString())); } return(right); }
public Context MakeContext(object argument, Context context) { Context newcontext = new Context(); if (!MatchUtilities.MatchObjects(this.head, argument, newcontext)) { return(null); } newcontext.SetParent(context); return(newcontext); }
public Context MakeContext(IList <object> arguments) { if (this.parameters.Count != arguments.Count) { return(null); } Context context = new Context(); for (int k = 0; k < this.parameters.Count; k++) { if (!MatchUtilities.MatchObjects(this.parameters[k], arguments[k], context)) { return(null); } } context.SetParent(this.context); return(context); }
public void NoMatchAtomInteger() { Context context = new Context(); Assert.IsFalse(MatchUtilities.MatchObjects(new Atom("a"), 123, context)); }
public void MatchAtoms() { Context context = new Context(); Assert.IsTrue(MatchUtilities.MatchObjects(new Atom("a"), new Atom("a"), context)); }