如果我有一个定义规则的序言文件,并在Windows的序言终端中将其打开,它将加载事实。但是,然后显示?-提示,让我手动输入内容。如何将代码添加到文件中,以便它实际上像对它们进行键入一样对那些特定的语句进行求值?

像这样的东西
dog.pl

dog(john).
dog(ben).

% execute this and output this right away when I open it in the console
dog(X).

有谁知道如何做到这一点?

谢谢

最佳答案

为此有一个ISO指令(以及更多):initialization
如果您有文件,请在文件夹中说出dog.pl并包含以下内容

dog(john).
dog(ben).

:- initialization forall(dog(X), writeln(X)).

当您查阅文件时,您会得到
?- [dog].
john
ben
true.

10-04 12:03
查看更多