How do I include a .pl file in Prolog?

旧街凉风 提交于 2019-12-22 01:13:29

问题


I'd like to include code from another source file. Does anyone know how to do that?


回答1:


If your file is called foo.pl, you can include it using

:- [foo].

or, equivalently and a bit more explicit

:- consult(foo).

or, if you're worried it may be loaded several times in a larger app

:- ensure_loaded(foo).

or, if you're using full-blown modules

:- use_module(foo).

though the exact name of the last predicate differs between Prolog versions.




回答2:


If you want to include the file literally - similar to #include, use :- include('file.pl').

Most of the time it is preferable to structure your program using modules, though.



来源:https://stackoverflow.com/questions/4097451/how-do-i-include-a-pl-file-in-prolog

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