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.
Declaration Syntax
C# | Visual Basic | Visual C++ | F# |
public PlQueryVariables Variables { get; }
Public ReadOnly Property Variables As PlQueryVariables Get
public: property PlQueryVariables^ Variables { PlQueryVariables^ get (); }
member Variables : PlQueryVariables with get
Property Value
Examples
In the following example you see how the query Variables can be used to set a variable.
Copy | |
---|---|
public void TestCompoundQueryWithVariables() { string[] refValues = { "x_a", "x_b", "x_c" }; using (new PlFrame()) { var 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(refValues[i++], (string)vars["L"]); } } } |
Here is a more complex sample where the variables of two queries are connected.
Copy | |
---|---|
public void TestCompoundNestedQueryWithVariables() { string[] refValues = { "x_a", "x_b", "x_c" }; string[] refValuesInner = { "a1", "a2", "b1", "b2", "c1", "c2" }; int innerIdx = 0; using (new PlFrame()) { var 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(refValues[i++], (string)vars["L"]); var 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(refValuesInner[innerIdx++], v.L); } } } } |
See Also
Assembly: SwiPlCs (Module: SwiPlCs.dll) Version: 1.1.60605.0 (1.1.60605.0)