0

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?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Ros
  • 37
  • 6

1 Answers1

1

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!

repeat
  • 18,496
  • 4
  • 54
  • 166
  • 1
    Thank you, but I don't know how can i solve this problem? – Ros Dec 27 '15 at 13:23
  • @K.Ros. How about trying `PlQuery.PlCall("read_all(datainput)"); PlQuery.PlCall("induce");` ? Or why do you need "assert(...)` when calling from C#, but not in the SWI-Prolog shell? – repeat Dec 27 '15 at 13:31
  • 1
    The application halts when run with 'PlQuery.PlCall("read_all(datainput)"); PlQuery.PlCall("induce")' – Ros Dec 27 '15 at 16:20
  • @K.Ros. One thing upfront: I cannot repeat the attempts you make/made, at least not right now... Could it be that the read-operation is waiting for data input? – repeat Dec 27 '15 at 20:12
  • 1
    Thank you, I run it with a sample test and it works. my 'datainput ' is all data ( 3 data files for use in Aleph) that I must review them. – Ros Dec 28 '15 at 18:22
  • The debug output is with such error: 'swi.vshost.exe' (CLR v4.0.30319: swi.vshost.exe): Loaded 'G:\testingpro\swi\swi\bin\Debug\swi.exe'. Symbols loaded. 'swi.vshost.exe' (CLR v4.0.30319: swi.vshost.exe): Loaded 'G:\testingpro\swi\swi\bin\Debug\SwiPlCs.dll'. Cannot find or open the PDB file. The thread 0x151c has exited with code 259 (0x103). The thread 0x5b8 has exited with code 0 (0x0). – Ros Dec 29 '15 at 17:51