locating the predicate in the named module.
Declaration Syntax
C# | Visual Basic | Visual C++ | F# |
public PlQuery( string module, string goal )
Public Sub New ( module As String, goal As String )
public: PlQuery( String^ module, String^ goal )
new : module : string * goal : string -> PlQuery
Remarks
Muddy Waters sang:"I'am build for comfort, I ain't build for speed"
Examples
Copy | |
---|---|
public void queryStringForeach() { string mm = "abc"; PlQuery q = new PlQuery("member(A, [a,b,c])"); int i = 0; foreach (PlTermV s in q.Solutions) { Assert.AreEqual(mm[i++].ToString(), s[0].ToString()); } // or with named variables i = 0; foreach (PlQueryVariables s in q.SolutionVariables) { Assert.AreEqual(mm[i++].ToString(), s["A"].ToString()); } } |
This sample shows a query with two variables.
Copy | |
---|---|
public void queryString2() { PlQuery q = new PlQuery("append(A, B, [a,b,c])"); Assert.IsTrue(q.NextSolution()); Assert.AreEqual("[]", q.Args[0].ToString()); Assert.AreEqual("[a,b,c]", q.Args[1].ToString()); Assert.IsTrue(q.NextSolution()); Assert.AreEqual("[a]", q.Args[0].ToString()); Assert.AreEqual("[b,c]", q.Args[1].ToString()); } |
And the same with named variables.
Copy | |
---|---|
public void queryStringNamed() { PlQuery q = new PlQuery("append(A, B, [a,b,c])"); Assert.IsTrue(q.NextSolution()); Assert.AreEqual("[]", q.Variables["A"].ToString()); Assert.AreEqual("[a,b,c]", q.Variables["B"].ToString()); Assert.IsTrue(q.NextSolution()); Assert.AreEqual("[a]", q.Variables["A"].ToString()); Assert.AreEqual("[b,c]", q.Variables["B"].ToString()); } |
This sample shows what happens if the argument vector is used with compound terms.
Copy | |
---|---|
public void PlCallQueryCompound_string() { string[] mm = { "comp(aa,aa1)", "comp(aa,aa2)", "comp(aa,aa3)" }; build_pred(); // create: test(comp(X,Y)) :- member(Z,[1,2,3]), atomic_list_concat([X,Z],Y). PlQuery q = new PlQuery("test(comp(aa,X))"); int i = 0; foreach (PlTermV s in q.Solutions) { Assert.AreEqual(mm[i++].ToString(), s[0].ToString()); } } |
And here how to get the results with named variables with compound terms.
Copy | |
---|---|
public void PlCallQueryCompoundNamed_string() { string[] mm = { "aa1", "aa2", "aa3" }; build_pred(); // create: test(comp(X,Y)) :- member(Z,[1,2,3]), atomic_list_concat([X,Z],Y). PlQuery q = new PlQuery("test(comp(aa,X))"); int i = 0; foreach (PlQueryVariables v in q.SolutionVariables) { Assert.AreEqual(mm[i++].ToString(), v["X"].ToString()); } } |
Assembly: SwiPlCs (Module: SwiPlCs.dll) Version: 1.1.60601.0 (1.1.60601.0)