1

I am running gprolog version 1.4.2 on a Fedora 17 Linux machine.

I wrote a small prolog program which runs fine. I defined a few predicates in it that I want to hoist out and use in other prolog programs. So I thought I would put them in a separate file and use the include directive (defined in sec 7.1.8 of the version 1.4.2 GNU Prolog manual). However, it didn't work. gprolog said those predicates (which were in the included file) were undefined.

So at the gprolog prompt I type:

| ?- include('tools.pro').

And I get:

uncaught exception: error(existence_error(procedure,include/1),top_level/0

So it clearly doesn't recognize the directive. I've searched all over and can't find any reason why this should happen. Any thoughts on this?

lurker
  • 56,987
  • 9
  • 69
  • 103

2 Answers2

1

As specified in the ISO Prolog standard, include/1 is a directive, not a predicate. GNU Prolog follows the official standard closely, thus you can not use include/1 as a predicate, including in a top-level query. As Sergey explained, if you want to load your programs, you can use the built-in predicate consult/1 or its shortcut ([Fie1, File, ...]).

To use the include/1 directive in your source files, write it preceded by the (:-)/1 operator. For example:

:- include('tools.pro').
Paulo Moura
  • 18,373
  • 3
  • 23
  • 33
  • Thanks Paulo. That worked great. I had missed the 'directive' versus 'predicate' description. I just couldn't find an example or explanation how to use it. The only puzzler for me now is what the GNU prolog manual says about it: "If it is not found it is then searched in each directory of parent includers." I'm not sure what 'parent includers' is referring to. – lurker Jun 04 '13 at 21:46
  • You're welcome. Regarding your question regarding the "parent includers", I assume that it refers to scenarios where a file includes a file that, in turn, include other file(s). – Paulo Moura Jun 04 '13 at 23:49
0

include/1 is for using in Prolog source files.

In the query prompt you probably just want to consult your source file: ['tools.pro'].

Sergii Dymchenko
  • 6,890
  • 1
  • 21
  • 46
  • Thanks. That did occur to me, but I did try compiling the program with the include and it still complained it couldn't find those predicates. – lurker Jun 04 '13 at 01:42
  • My original problem was that the include isn't being recognized in a compiled program. I ran it manually at the prompt as a test. Your answer explains why that manual test doesn't work, so I understand that now. But my original problem still exists, unfortunately. – lurker Jun 04 '13 at 11:02
  • Can you show your Prolog source file where `include/1` is used? – Sergii Dymchenko Jun 04 '13 at 18:02
  • I just had it as `include('../tools.pro').` at the top of the file. – lurker Jun 04 '13 at 21:48