Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 799
cody Avatar asked Nov 04 '10 14:11

cody


People also ask

How do I load a .pl file in Prolog?

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.

What is Prolog extension?

By default, Prolog uses the . pl extension to indicate Prolog source files.


2 Answers

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.

like image 57
Fred Foo Avatar answered Sep 20 '22 09:09

Fred Foo


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.

like image 33
false Avatar answered Sep 19 '22 09:09

false