Beispiel #1
0
        public void MatchVariableInverse()
        {
            Context context = new Context();

            Assert.IsTrue(MatchUtilities.MatchObjects(1, new Variable("X"), context));

            Assert.AreEqual(1, context.GetValue("X"));
        }
Beispiel #2
0
        public void MatchAnonymousVariable()
        {
            Context context = new Context();

            Assert.IsTrue(MatchUtilities.MatchObjects(new Variable("_"), 1, context));

            Assert.IsNull(context.GetValue("_"));
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public void NoMatchAtomInteger()
        {
            Context context = new Context();

            Assert.IsFalse(MatchUtilities.MatchObjects(new Atom("a"), 123, context));
        }
Beispiel #7
0
        public void MatchAtoms()
        {
            Context context = new Context();

            Assert.IsTrue(MatchUtilities.MatchObjects(new Atom("a"), new Atom("a"), context));
        }