如何从 swi-prolog 的 prolog 文件中运行 prolog 查询? [英] How to run prolog queries from within the prolog file in swi-prolog?
本文介绍了如何从 swi-prolog 的 prolog 文件中运行 prolog 查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个定义规则的 prolog 文件,并在 windows 的 prolog 终端中打开它,它会加载事实.但是,它会显示 ?-
提示,让我手动输入内容.如何将代码添加到文件中,以便它实际评估这些特定语句,就像我输入它们一样?
If I have a prolog file defining the rules, and open it in a prolog terminal in windows, it loads the facts. However, then it shows the ?-
prompt for me to manually type something. How can I add code to the file, so that it will actually evaluate those specific statements as if I typed them in?
像这样
dog.pl
dog(john).
dog(ben).
% execute this and output this right away when I open it in the console
dog(X).
有人知道怎么做吗?
谢谢
推荐答案
有一个 ISO 指令 用于此目的(以及更多):初始化如果你有一个文件,在文件夹中说 dog.pl,有这个内容
There is an ISO directive on this purpose (and more): initialization If you have a file, say dog.pl in a folder, with this content
dog(john).
dog(ben).
:- initialization forall(dog(X), writeln(X)).
当你查阅你得到的文件
?- [dog].
john
ben
true.
这篇关于如何从 swi-prolog 的 prolog 文件中运行 prolog 查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文