如何在 SWI-Prolog 中创建一个事实? [英] How to create a fact in SWI-Prolog?
问题描述
我只想创建类似:like(x,y)
.我已经尝试了很长时间,真的很沮丧,谁能告诉我该怎么做???!!!
I just want to create something like: like(x,y)
.
I've been trying for a long time and am really frustrated, could anyone please tell me how to do it???!!!
推荐答案
我假设您正在以交互方式使用 swi 并尝试输入事实会给您这样的错误:
I'm assuming you are using swi interactively and trying to enter the fact gives you an error like so:
1 ?- like(x, y).
ERROR: toplevel: Undefined procedure: like/2 (DWIM could not correct goal)
由于该事实在数据库中不存在.如果是这种情况,请先尝试断言事实:
Since the fact does not exist in the database. If this is the case, try asserting the fact first:
2 ?- assert(like(x,y)).
true.
那你可以试试:
3 ?- like(x, y).
true.
这次查询成功,因为事实存在于数据库中.
This time the query succeeds because the fact exists in the database.
更好的方法可能是将您的子句写入文件 &然后咨询他们.Swi prolog 有一个类似 emacs 的编辑器,你可以输入
A better approach might be to write your clauses into a file & then consult them. Swi prolog has an emacs-like editor that you can bring up by typing
emacs.
在提示下.或使用您自己的编辑器 &然后查阅文件.Swi序言附带许多可能有帮助的图形工具;看说明书了解更多详情.
at the prompt. Or use your own editor & then consult the file. Swi prolog comes with a lot of graphical tools that might be of help; look at the manual for more details.
这篇关于如何在 SWI-Prolog 中创建一个事实?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!