Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog
Variables Property
SwiPlCs interface ► SbsSW.SwiPlCs ► PlQuery ► Variables
The List of PlQueryVariables of this PlQuery.

C# | Visual Basic | Visual C++ |
public PlQueryVariables Variables { get; }
Public ReadOnly Property Variables As PlQueryVariables Get
public: property PlQueryVariables^ Variables { PlQueryVariables^ get (); }

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

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.

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); } } } }
