![](/img/trans.png)
[英]Getting Result from a Prolog Query in C# using SWI-Prolog C#
[英]Using Aleph in C# with SWI Prolog?
在 C# 應用程序中,我想使用 Aleph 來構建理論。
以下在 SWI-Prolog 中有效:
?- [aleph.pl]. ?- working_directory(CDW,'C:/Users/admin/Desktop/inputFiles'). ?- read_all(datainput). ?- induce.
但在 C# 中,這些命令不會:
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)"); }
我收到PlQuery.PlCall("assert(read_all(datainput))")
的以下錯誤:
SwiPlCs.dll 中出現類型為“SbsSW.SwiPlCs.Exceptions.PlException”的未處理異常詳細信息:SbsSW.SwiPlCs.Exceptions.PlException 未處理 HResult=-2146233088 消息=斷言/1:無權修改靜態過程`read_all/1 ' 定義在 c:/users/admin/desktop/aleph_pack/aleph.pl:8857
我該如何解決這個錯誤?
使用 C# 而不是直接使用 Prolog 時出現錯誤的原因是:
你在做兩件不同的事情!
讓我們交錯上面的兩個片段:
?- read_all(datainput) . %% PlQuery.PlCall("assert(read_all(datainput))"); ?- induce . %% PlQuery.PlCall("assert(induce)");
因此,您在 C# 代碼中使用了prolog-assert ,但沒有在交互式 SWI-Prolog 會話中使用。
您得到的多行錯誤的一部分也指向那個方向:
assert/1: No permission to modify static procedure `read_all/1'
通過思考這個差異來繼續你的調查。 如果您的代碼的舊版本表現出不同的行為,也請檢查它們(以及當前代碼的增量)!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.