3
votes

I want to use SWI PROLOG wrapper for C#. My friend created some code in prolog on normal SWI PROLOG. I want to execute this in c# using SwiPLCs.dll. I want to make from his code my knowledge base.

I was looking at demo code. They were passing prolog lines like that:

PlQuery.PlCall("assert(father(martin, inka))");

My friends code looks like that:

:-  dynamic(releases/4),dynamic(preserve/3).
neg(X,Y) :- sneg(Y,X).
neg(X,Y) :- sneg(X,Y).
neg(X,X) :- !,fail.
inertial(X) :- sinertial(X).
inertial(X) :- neg(X,Y),
           sinertial(Y).

It's a lot longer, but i pasted just few lines. I wrapped all lines with this call: PlQuery.PlCall("assert(line_of_code)");

At first line I'm getting this exception:

assert/2: Uninstantiated argument expected, found dynamic preserve/3 (2-nd argument)

At the 4th line I'm getting this exception:

Syntax error: Operator expected\nassert(neg(X,X) :- !,fai\n** here **\nl.\r

What am I doing wrong? I just want to execute some fixed code to initialize my prolog engine. Can I simply execute it like normal prolog code and then use the features of this wrapper?

1

1 Answers

3
votes

you could try to add further parenthesis:

PlQuery.PlCall("assert((line_of_code))");

this should solve some of your problems.

But if the engine can access the source file, it's simpler to consult it

PlQuery.PlCall("consult('"+file_path+"')");