I'd like to include code from another source file. Does anyone know how to do that?
pl extension is associated with swipl-win.exe and most comfortable way is to double-click the . pl file you want to load in the explorer. This will start SWI-Prolog, which changes directory to the directory holding the file and then loads the clicked file.
By default, Prolog uses the . pl extension to indicate Prolog source files.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With