0

在 C# 应用程序中,我想使用 Aleph 来构建理论。

以下在 SWI-Prolog 中起作用:

?- [aleph.pl]。

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

?- read_all(数据输入)。

?-诱导。

但在 C# 中,这些命令不会:

if (!PlEngine.IsInitialized)
{
    字符串[] 参数 = { "-q" };    
    PlEngine.Initialize(参数);

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

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

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

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

我收到以下错误 PlQuery.PlCall("assert(read_all(datainput))")

SwiPlCs.dll 中出现“SbsSW.SwiPlCs.Exceptions.PlException”类型的未处理异常
细节:
SbsSW.SwiPlCs.Exceptions.PlException 未处理
 H结果=-2146233088
 Message=assert/1:无权修改静态过程“read_all/1”
 定义在 c:/users/admin/desktop/aleph_pack/aleph.pl:8857

我该如何解决这个错误?

4

1 回答 1

1

使用 C# 时会出现错误,但直接使用 Prolog 时不会出现错误的原因是:

你在做两件不同的事情!

让我们交错上面的两个片段:

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

?-诱导。
%% PlQuery.PlCall("断言(诱导) ");

因此,您在 C# 代码中使用,而不是在交互式 SWI-Prolog 会话中。

您得到的多行错误的一部分也指向该方向:

assert/1 : 无权修改静态过程 `read_all/1'

通过思考这种差异来恢复你的调查。如果您的代码的旧版本表现出不同的行为,请检查它们(以及当前代码的增量)!

于 2015-12-27T09:21:03.170 回答