Example #1
0
        public void PrologPredicateCallingExternalPredicateTest()
        {
            var externalPredicate = new ExternalPredicateDeclaration("externalPredicate", 1);

            Compiled.Program program = Compiler.Compile(new AST.Program(new []
            {
                new AST.Clause
                {
                    Head = Helper.MakeGoal("callExternalPredicate", "X"),
                    Body = new [] { Helper.MakeGoal("externalPredicate", "X") }
                }
            }, new []
            {
                externalPredicate
            }));

            program.SetExternalPredicateCallbacks(
                new []
            {
                new KeyValuePair <ExternalPredicateDeclaration, ExternalPredicateDefinition> (externalPredicate, new SampleExternalPredicate("john").BindVariables)
            }
                );

            var goal = Helper.MakeGoal("callExternalPredicate", "X");

            AssertExternalPredicateSolutionIsCorrect(goal, program);
        }
Example #2
0
        public void ExternalPredicateReturningMulpipleAnswersTest()
        {
            var externalPredicate = new ExternalPredicateDeclaration("externalPredicate", 1);

            Compiled.Program program = Compiler.Compile(new AST.Program(new AST.Clause []
            {
            }, new []
            {
                externalPredicate
            }));

            program.SetExternalPredicateCallbacks(
                new []
            {
                new KeyValuePair <ExternalPredicateDeclaration, ExternalPredicateDefinition> (externalPredicate, new SampleExternalPredicate("john", "jane").BindVariables)
            }
                );

            var goal = Helper.MakeGoal("externalPredicate", "X");

            var solutions = Helper.GetSolutions(goal, program).ToArray();

            Assert.AreEqual(2, solutions.Length);

            Assert.AreEqual("john", ((Runtime.Atom)solutions [0] ["X"]).Name);
            Assert.AreEqual("jane", ((Runtime.Atom)solutions [1] ["X"]).Name);
        }
Example #3
0
        public void PrologPredicateCallingExternalPredicateTest()
        {
            var externalPredicate = new ExternalPredicateDeclaration ("externalPredicate", 1);

            Compiled.Program program = Compiler.Compile (new AST.Program (new []
                                                                                     {
                                                                                         new AST.Clause
                                                                                             {
                                                                                                 Head = Helper.MakeGoal ("callExternalPredicate", "X"),
                                                                                                 Body = new [] {Helper.MakeGoal ("externalPredicate", "X")}
                                                                                             }
                                                                                     }, new []
                                                                                            {
                                                                                                externalPredicate
                                                                                            }));

            program.SetExternalPredicateCallbacks (
                new []
                {
                    new KeyValuePair <ExternalPredicateDeclaration, ExternalPredicateDefinition> (externalPredicate, new SampleExternalPredicate("john").BindVariables)
                }
            );

            var goal = Helper.MakeGoal ("callExternalPredicate", "X");

            AssertExternalPredicateSolutionIsCorrect (goal, program);
        }
Example #4
0
 public Program (Clause [] clauses, ExternalPredicateDeclaration [] externalPredicateDeclarations = null) : this ()
 {
     this.Clauses = clauses;
     this.ExternalPredicates = externalPredicateDeclarations;
 }
Example #5
0
        public void ExternalPredicateReturningMulpipleAnswersTest()
        {
            var externalPredicate = new ExternalPredicateDeclaration ("externalPredicate", 1);

            Compiled.Program program = Compiler.Compile (new AST.Program (new AST.Clause []
                                                                                     {
                                                                                     }, new []
                                                                                            {
                                                                                                externalPredicate
                                                                                            }));

            program.SetExternalPredicateCallbacks (
                new []
                {
                    new KeyValuePair <ExternalPredicateDeclaration, ExternalPredicateDefinition> (externalPredicate, new SampleExternalPredicate("john", "jane").BindVariables)
                }
            );

            var goal = Helper.MakeGoal ("externalPredicate", "X");

            var solutions = Helper.GetSolutions (goal, program).ToArray();

            Assert.AreEqual (2, solutions.Length);

            Assert.AreEqual ("john", ((Runtime.Atom) solutions [0] ["X"]).Name);
            Assert.AreEqual ("jane", ((Runtime.Atom) solutions [1] ["X"]).Name);
        }