Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog
PlQuery Constructor (module, goal)
SwiPlCs interfaceSbsSW.SwiPlCsPlQueryPlQuery(String, String)
locating the predicate in the named module.
Declaration Syntax
C#Visual BasicVisual 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
Parameters
module (String)
locating the predicate in the named module.
goal (String)
A string for a prolog query
Remarks
Muddy Waters sang:"I'am build for comfort, I ain't build for speed"
Examples
 Copy imageCopy
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 imageCopy
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 imageCopy
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 imageCopy
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 imageCopy
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)