![Copy image Copy image](icons/copycode.gif)
![CopyHover image CopyHover image](copycodeHighlight.gif)
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.
![](collapse_all.gif)
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
![](collapse_all.gif)
![](collapse_all.gif)
In the following example you see how the query Variables can be used to set a variable.
![]() |
|
---|---|
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.
![]() |
|
---|---|
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); } } } } |
![](collapse_all.gif)
Assembly: SwiPlCs (Module: SwiPlCs.dll) Version: 1.1.60605.0 (1.1.60605.0)