在Prolog中加载文件

时间:2010-12-21 03:18:04

标签: prolog

我正在阅读Prolog教程。它告诉我我可以输入以下内容加载其他prolog文件:

[filename].

但每次我尝试这件事都

ERROR: load_files/2: Arguments are not sufficiently instantiated.

该文件与正在处理的文件位于同一目录中。

以下是整个查询和错误的副本:

12 ?- [KB5].

ERROR: load_files/2: Arguments are not sufficiently instantiated

我做错了什么?

3 个答案:

答案 0 :(得分:24)

$ cat junk.pl
test(ok).

$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.8.0)
Copyright (c) 1990-2009 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [junk].
% junk compiled 0.00 sec, 24 bytes
true.

它对我来说似乎很好。当然我使用原子作为我的文件名,而不是变量。 (KB5是变量名,而不是原子。)首先尝试['KB5']并查看是否有帮助。接下来尝试[kb5],看看是否有帮助。最后尝试一个绝对最小的例子,就像我提供的一样,看看你是否可以这样加载。


已编辑添加:

$ cp junk.pl JUNK.pl
$ prolog
Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 5.8.0)
Copyright (c) 1990-2009 University of Amsterdam.
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.

For help, use ?- help(Topic). or ?- apropos(Word).

?- [JUNK].
ERROR: load_files/2: Arguments are not sufficiently instantiated
?- ['JUNK'].
% JUNK compiled 0.00 sec, 1,656 bytes
true.

看起来确实是原子问题。使用['KB5'],您的错误可能会消失。

答案 1 :(得分:9)

虽然提供的其他方法有效。这是另一种选择:

?- consult('C:/User/Folder/myRules.pl').

这应该可以做到!

答案 2 :(得分:0)

没说你正在使用什么平台。我在Raspberry Pi上运行,如果它们放在Pi目录中,prolog文件加载正常。我无法将它们加载到Pi / Documents目录中。所以我在Pi目录中进行了实验并创建了一个“prolog”文件夹,并将我的load.pl文件放在那里,现在可以查阅了。

consult(prolog/load).
相关问题