Swi-cs-pl - A CSharp class library to connect .NET languages with SWI-Prolog
PlEngine Class
SwiPlCs interface ► SbsSW.SwiPlCs ► PlEngine
This static class represents the prolog engine.
Declaration Syntax
C# | Visual Basic | Visual C++ | F# |
public static class PlEngine
Public NotInheritable Class PlEngine
public ref class PlEngine abstract sealed
[<AbstractClassAttribute>] [<SealedAttribute>] type PlEngine = class end
Members
All Members | Methods | Properties | |||
|
|
|
Icon | Member | Description |
---|---|---|
Initialize(array<String>[]()[][]) |
Initialise SWI-Prolog The write method of the output stream is redirected to SbsSW.SwiPlCs.Streams before Initialize. The read method of the input stream just after Initialize. |
|
IsInitialized |
To test if the prolog engine is up.
|
|
PlCleanup()()()() |
Try a clean up but it is buggy
search the web for "possible regression from pl-5.4.7 to pl-5.6.27" to see reasons
|
|
PlHalt()()()() |
Stops the PlEngine and the program
|
|
PlThreadAttachEngine()()()() |
return : reference count of the engine If an error occurs, -1 is returned. If this Prolog is not compiled for multi-threading, -2 is returned. |
|
PlThreadDestroyEngine()()()() |
Destroy the Prolog engine in the calling thread.
Only takes effect if PL_thread_destroy_engine() is called as many times as PL_thread_attach_engine() in this thread.
Please note that construction and destruction of engines are relatively expensive operations. Only destroy an engine if performance is not critical and memory is a critical resource. |
|
PlThreadSelf()()()() |
This method is also provided in the single-threaded version of SWI-Prolog, where it returns -2.
|
|
RegisterForeign(Delegate) |
Register a C# callback method |
|
RegisterForeign(String, Delegate) |
Register a C# callback method |
|
RegisterForeign(String, Int32, Delegate) |
Register a C# callback method |
|
RegisterForeign(String, String, Int32, Delegate) |
Register a C# callback method |
|
SetStreamFunctionRead(PlStreamType, DelegateStreamReadFunction) |
TODO
|
|
SetStreamFunctionWrite(PlStreamType, DelegateStreamWriteFunction) |
This is a primitive approach to enter the output from a stream.
|
Examples
A sample
The following sample show how a file is consult via comand-line options.
Copy | |
---|---|
if (!PlEngine.IsInitialized) { String[] empty_param = { "" }; PlEngine.Initialize(empty_param); // do some funny things ... PlEngine.PlCleanup(); } // program ends here |
Copy | |
---|---|
public void Demo_consult_pl_file_by_param() { string[] ref_values = { "gloria", "melanie", "ayala" }; Console.WriteLine("Demo_consult_pl_file_by_param"); // Build a prolog source file (skip this step if you already have one :-) string filename = Path.GetTempFileName(); StreamWriter sw = File.CreateText(filename); sw.WriteLine("father(martin, inka)."); sw.WriteLine("father(uwe, gloria)."); sw.WriteLine("father(uwe, melanie)."); sw.WriteLine("father(uwe, ayala)."); sw.Close(); // build the parameterstring to Initialize PlEngine with the generated file String[] param = { "-q", "-f", filename }; try { PlEngine.Initialize(param); Console.WriteLine("all child's from uwe:"); using (PlQuery q = new PlQuery("father(uwe, Child)")) { int idx = 0; foreach (PlQueryVariables v in q.SolutionVariables) { Console.WriteLine(v["Child"].ToString()); Assert.AreEqual(ref_values[idx++], v["Child"].ToString()); } } } catch (PlException e) { Console.WriteLine(e.MessagePl); Console.WriteLine(e.Message); } finally { PlEngine.PlCleanup(); } } // Demo_consult_pl_file_by_param |
Inheritance Hierarchy
Object | |
PlEngine |
See Also
Assembly: SwiPlCs (Module: SwiPlCs.dll) Version: 1.1.60605.0 (1.1.60605.0)