Why isn't father/2
recognized and why can't I load a file that calls father/2
?
theogony.pl
father(kronos, zeus).
father(zeus, ares).
mythos.pl
consult('theogony.pl').
%% --
%% X is an ancestor of Y
%% --
ancestor(X,Y) :-
father(X,Y).
ancestor(X,Y) :-
ancestor(X,Z),
ancestor(Z,Y).
swipl
?- consult('mythos.pl').
false.
?- consult('theogony.pl').
true.
?- father(X,zeus).
ERROR: Unknown procedure: father/2 (DWIM could not correct goal)
As noted there are two Prolog files with the file type pl
. This code works with both files in the same directory, eg 'C:/Users/Groot/Example_01'. You can use another directory but be consistent with the directory name.
Directory: 'C:/Users/Groot/Example_01'
File: 'theogony.pl'
:- module(theogony,
[
father/2
]).
father(kronos, zeus).
father(zeus, ares).
Directory: 'C:/Users/Groot/Example_01'
File: 'mythos.pl'
:- module(mythos,
[
ancestor/2
]).
ancestor(X,Y) :-
father(X,Y).
ancestor(X,Y) :-
ancestor(X,Z),
ancestor(Z,Y).
Start SWI-Prolog
Welcome to SWI-Prolog (threaded, 64 bits, version 8.5.15)
...
?-
I know, there is a newer version but this is so basic even the really old versions should work.
Change the working directory.
?- working_directory(_,'C:/Users/Groot/Example_01').
true.
Use consult which is also done using []
to load the Prolog files.
?- [theogony].
true.
?- [mythos].
true.
Run your query.
?- father(X,zeus).
X = kronos.
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.