DelegateParameterVarArgs Delegate

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog DelegateParameterVarArgs Delegate
SwiPlCs interfaceSbsSW.SwiPlCs.CallbackDelegateParameterVarArgs

With this delegate you can build a call-back predicate with a variable amount of parameters.

Declaration Syntax
C# Visual Basic Visual C++
public delegate bool DelegateParameterVarArgs(
	PlTermV termVector
)
Public Delegate Function DelegateParameterVarArgs ( _
	termVector As PlTermV _
) As Boolean
public delegate bool DelegateParameterVarArgs(
	PlTermV termVector
)
Parameters
termVector (PlTermV)
The termVector representing the arguments which can be accessed by the indexer of PlTermV see PlTermV. The amount of parameters is in Size
Return Value
True for succeeding otherwise false for fail
Examples
CopyC#
public void t_varargs()
{
    Delegate d = new DelegateParameterVarArgs(my_concat_atom);
    PlEngine.RegisterForeign("my_concat_atom", 4, d);
    PlEngine.RegisterForeign("my_concat_atom", 7, d);
    for (int i = 1; i < 10; i++)
    {
        PlTerm t = PlQuery.PlCallQuery("my_concat_atom(a,b,c, X)");
        Assert.AreEqual("abc", t.ToString(), "my_concat_atom failed!");
        t = PlQuery.PlCallQuery("my_concat_atom(a,b,c,d,e,f, X)");
        Assert.AreEqual("abcdef", t.ToString(), "my_concat_atom failed!");
    }
}
public static bool my_concat_atom(PlTermV term1)
{
    int arity = term1.Size;
    string sRet = "";
    PlTerm term_out = term1[arity -1];

    for (int i = 0; i < arity-1; i++)
    {
        string s = term1.ToString();
        sRet += term1[i].ToString();
    }
    term_out.Unify(sRet);
    return true;
}

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