PlFrame Class

SWI-Prolog SbsSW.SwiPlCs

Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog PlFrame Class
SwiPlCs interfaceSbsSW.SwiPlCsPlFrame

The class PlFrame provides an interface to discard unused term-references as well as rewinding unifications (data-backtracking). Reclaiming unused term-references is automatically performed after a call to a C#-defined predicate has finished and returns control to Prolog. In this scenario PlFrame is rarely of any use.

This class comes into play if the top level program is defined in C# and calls Prolog multiple times. Setting up arguments to a query requires term-references and using PlFrame is the only way to reclaim them.

Declaration Syntax
C# Visual Basic Visual C++
public class PlFrame : IDisposable
Public Class PlFrame _
	Implements IDisposable
public ref class PlFrame : IDisposable
Members
All Members Constructors Methods



Icon Member Description
PlFrame()()()()
Creating an instance of this class marks all term-references created afterwards to be valid only in the scope of this instance.

Dispose()()()()
Implement IDisposable.

Equals(Object)
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Finalize()()()()
Reclaims all term-references created after constructing the instance.
(Overrides Object.Finalize()()()().)
GetHashCode()()()()
Serves as a hash function for a particular type.
(Inherited from Object.)
GetType()()()()
Gets the Type of the current instance.
(Inherited from Object.)
MemberwiseClone()()()()
Creates a shallow copy of the current Object.
(Inherited from Object.)
Rewind()()()()
Discards all term-references and global-stack data created as well as undoing all unifications after the instance was created.

ToString()()()()
Returns a String that represents the current Object.
(Inherited from Object.)
Examples
A typical use for PlFrame is the definition of C# methods that call Prolog and may be called repeatedly from C#. Consider the definition of assertWord(), adding a fact to word/1:
CopyC#
void AssertWord2(string word)
{
    PlFrame fr = new PlFrame();
    PlTermV av = new PlTermV(1);
    av[0] = PlTerm.PlCompound("word", new PlTermV(new PlTerm(word)));
    PlQuery q = new PlQuery("assert", av);
    q.NextSolution();
    q.Dispose();   // IMPORTANT ! never forget to free the query before the PlFrame is closed
    fr.Dispose();
}
alternatively you can use
CopyC#
void AssertWord(string word)
{
    using (PlFrame fr = new PlFrame())
    {
        PlTermV av = new PlTermV(1);
        av[0] = PlTerm.PlCompound("word", new PlTermV(new PlTerm(word)));
        using (PlQuery q = new PlQuery("assert", av))
        {
            q.NextSolution();
        }
    }
}
Caution: NOTE: in any case you have to destroy any query object used inside a PlFrame
Inheritance Hierarchy
Object
PlFrame

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