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); }
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); }
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); }
public Program (Clause [] clauses, ExternalPredicateDeclaration [] externalPredicateDeclarations = null) : this () { this.Clauses = clauses; this.ExternalPredicates = externalPredicateDeclarations; }
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); }