SWI Prolog ensure_loaded error

我的梦境 提交于 2019-12-06 09:01:34

问题


I am using SWI Prolog for a mathematical logic book and the book provided source code for some of the algorithms in Prolog. The problem is that when I try to load a file, the interpreter just prompt something like:

load_files/2: No permission to load source `**' (Non-module file already loaded into module **; trying to load into io)

I looked into the source code and found that most of the files start with:

:- module(**,[***]).

followed by

user:file_search_path(common,'../common').
:- ensure_loaded(ops).
:- ensure_loaded(def).

and it seems that calling ensure_loaded twice with the same file caused the error, and if some of the predicates in the already loaded file (ops.pl for example) will not be defined in the file that tried to load it for the second time.

I tried changing ensure_loaded to use_module and consult but didn't work.


回答1:


I solved the problem by moving all the ensure_loaded to one file.




回答2:


I just ran into this problem myself.

?- [test].
Warning: test.pl:1:
        test is not a current module (created)
% test compiled 0.00 sec, 3 clauses
true.

Perform an edit on the file and then reconsult and you'll have the problem:

test:  ?- [test].
ERROR: load_files/2: No permission to load source `test.pl' 
       (Non-module file already loaded into module user; trying to load into test)

Solution: use make/0:

test:  ?- make.
% Updating index for library <snip>/packages/pl-6.2.2/lib/swipl-6.2.2/library/
% test compiled 0.00 sec, 2 clauses
true.

Now your changes are loaded.



来源:https://stackoverflow.com/questions/9518216/swi-prolog-ensure-loaded-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!