Variables Property

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog Variables Property
SwiPlCs interfaceSbsSW.SwiPlCsPlQueryVariables
The List of PlQueryVariables of this PlQuery.
Declaration Syntax
C# Visual Basic Visual C++
public PlQueryVariables Variables { get; }
Public ReadOnly Property Variables As PlQueryVariables
	Get
public:
property PlQueryVariables^ Variables {
	PlQueryVariables^ get ();
}
Examples

In the following example you see how the query Variables can be used to set a variable.

CopyC#
public void TestCompoundQueryWithVariables()
{
    string[] ref_values = { "x_a", "x_b", "x_c" };
    using (PlFrame fr = new PlFrame())
    {
        PlQuery plq = new PlQuery("member(X, [a,b,c]), atomic_list_concat([P, X], L)");
        plq.Variables["P"].Unify("x_");
        int i = 0;
        foreach (PlQueryVariables vars in plq.SolutionVariables)
        {
            Assert.AreEqual("x_", (string)vars["P"]);
            Assert.AreEqual(ref_values[i++], (string)vars["L"]);
        }
    }
}

Here is a more complex sample where the variables of two queries are connected.

CopyC#
public void TestCompoundNestedQueryWithVariables()
{
    string[] ref_values = { "x_a", "x_b", "x_c" };
    string[] ref_values_inner = { "a1", "a2", "b1", "b2", "c1", "c2" };
    int inner_idx = 0;
    using (PlFrame fr = new PlFrame())
    {
        PlQuery plq = new PlQuery("member(X, [a,b,c]), atomic_list_concat([P, X], L)");
        plq.Variables["P"].Unify("x_");
        int i = 0;
        foreach (PlQueryVariables vars in plq.SolutionVariables)
        {
            Assert.AreEqual("x_", (string)vars["P"]);
            Assert.AreEqual(ref_values[i++], (string)vars["L"]);
            PlQuery q = new PlQuery("member(X, [1,2]), atomic_list_concat([P, X], L)");
            q.Variables["P"].Unify(plq.Variables["X"]);
            var results = from n in q.ToList() select new { L = n["L"].ToString() };
            foreach (var v in results)
            {
                Assert.AreEqual(ref_values_inner[inner_idx++], v.L);
            }
        }
    }
}
See Also

Assembly: SwiPlCs (Module: SwiPlCs) Version: 1.1.60301.0 (1.1.60301.0)