我写了一些prolog逻辑,如何编写使用它的脚本?

时间:2013-03-27 00:13:38

标签: prolog swi-prolog

我正在为一个prolog课程编写一个作业,而我却坚持做一些简单的事情。我在一个名为question1.pl

的文件中写了一堆逻辑

我在Mac OS X上使用SWI,所以在命令提示符下我这样做:

swilg
consult('question1.pl').

加载文件,然后测试它我做:

?- father(homer,bart).
true
?- father(marge,bart).
false

等等。

我的问题是,如何为我的代码编写“测试脚本”?

我假设我应该写一些像question1-tests.pl这样的东西:

(write 'test1, should be true').
father(homer,bart).
(write 'test2, should be false').
father(marge,bart).

但是如何运行该脚本?

抱歉,我知道这很简单,但我被困住了。谢谢!

2 个答案:

答案 0 :(得分:1)

不确定这是否是最佳方式,但您可以制作如下脚本:

swipl <<END
[question1].
write('test1, should be true').
father(homer,bart).
write('test2, should be false').
father(marge,bart).
END

答案 1 :(得分:0)

回答我自己的问题,我发现我可以将它添加到我的问题1.pl ...

doTests:-write('Test1, should be true'),nl,father(homer,bart).

只需运行

?- doTests

获得输出。足以满足我的任务需求。