Using Aleph in C# with SWI Prolog?

343 Views Asked by At

In a C# application, I want to use Aleph for constructing a theory.

The following works in SWI-Prolog:

?- [aleph.pl].

?- working_directory(CDW,'C:/Users/admin/Desktop/inputFiles').

?- read_all(datainput).

?- induce.

But in C# these commands don't:

if (!PlEngine.IsInitialized)
{
    String[] param = { "-q" };    
    PlEngine.Initialize(param);

    PlQuery.PlCall("consult('C:/Users/admin/Desktop/Aleph_pack/Aleph.pl')");

    PlQuery.PlCall("working_directory(CDW,'C:/Users/admin/Desktop/inputFiles'));

    PlQuery.PlCall("assert(read_all(datainput))");   // ERROR!

    PlQuery.PlCall("assert(induce)");
}

I get the following error for PlQuery.PlCall("assert(read_all(datainput))"):

An unhandled exception of type 'SbsSW.SwiPlCs.Exceptions.PlException' occurred in SwiPlCs.dll
Details:
SbsSW.SwiPlCs.Exceptions.PlException was unhandled
 HResult=-2146233088
 Message=assert/1: No permission to modify static procedure `read_all/1'
 Defined at c:/users/admin/desktop/aleph_pack/aleph.pl:8857

How can I fix this error?

1

There are 1 best solutions below

6
On

The reason why you get the error with C#, but not when using Prolog directly, is this:

You are doing two different things!

Let's interleave the above two snippets:

?-                        read_all(datainput)   .
%% PlQuery.PlCall("assert(read_all(datainput))");

?-                        induce   .
%% PlQuery.PlCall("assert(induce)");

So you are using in the C# code, but not in the interactive SWI-Prolog session.

A part of the multi-line error you got, points in that direction, too:

assert/1: No permission to modify static procedure `read_all/1'

Resume your investigation by pondering on that difference. If you have older versions of your code that exhibited different behaviour, examine them (and the delta to the current code), too!