简体   繁体   中英

How do I include a .pl file in Prolog?

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM