Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog
Item Property (pos)
SwiPlCs interface ► SbsSW.SwiPlCs ► PlTerm ► Item[([( Int32])])
If PlTerm is compound and index is between 0 and Arity (including), the nth PlTerm is returned.
If pos is 0 the functor of the term is returned (For a list '.').
See: PL_get_arg/3
Declaration Syntax
Parameters
- pos (Int32)
- To Get the nth PlTerm
Return Value
a PlTerm
Examples
CopyC#
[TestMethod] public void PlTermIndexer2() { PlTerm t = PlTerm.PlCompound("foo(bar, x(y))"); Assert.AreEqual("foo", t[0].ToString()); Assert.AreEqual("bar", t[1].ToString()); Assert.AreEqual("x(y)", t[2].ToString()); } [TestMethod] public void PlTermIndexer_list1() { PlTerm t = PlTerm.PlCompound("[a,b,c]"); Assert.AreEqual(".", t[0].ToString()); Assert.AreEqual("a", t[1].ToString()); Assert.AreEqual("[b,c]", t[2].ToString()); }
Exceptions
Exception | Condition |
---|---|
NotSupportedException | Is thrown if PlTerm is not of Type PlCompound see IsCompound |
ArgumentOutOfRangeException | Is thrown if (pos < 0 || pos >= Arity) |
InvalidOperationException | Is thrown if PL_get_arg returns 0. |