문제

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?

도움이 되었습니까?

해결책

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').

다른 팁

include/1 is for using in Prolog source files.

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top