Reputation: 59
I'm still learning prolog but am coming across this error.
Warning: /usr/local/home/jay275/SDRIVE/cs3500/hw7/part1.pl:23:
Clauses of bird/1 are not together in the source-file
Earlier definition at /usr/local/home/jay275/SDRIVE/cs3500/hw7/part1.pl:10
Current predicate: animal/1
Use :- discontiguous bird/1. to suppress this message
I'm trying to say that if hawk then it is a bird. If it's a bird then it's a animal... etc..
Here is my code:
cat(sylvester).
cat(felix).
dog(spike).
dog(fido).
primate(george).
primate("king kong").
bird(tweety).
hawk(tony).
fish(nemo).
%then Mammal if cat or dog or primate
mammal(X) :- cat(X) ; dog(X) ; primate(X).
%then Animal if mammal or bird or fish
animal(X) :- mammal(X) ; bird(X) ; fish(X).
%then bird if hawk
bird(X) :- hawk(X).
EDIT: I don't think this error is actually causing any issues, but I'm just making sure I'm not doing anything incorrect.
EDIT2: TAS answered my question by placing the following code together.
bird(tweety).
%then bird if hawk
bird(X) :- hawk(X).
hawk(tony).
Upvotes: 3
Views: 89
Reputation: 8140
The message informs you that the clauses of your predicate bird/1 are at different positions in your source file, namely line 10 (bird(tweety).
) and line 23 (bird(X) :- hawk(X).
). There are clauses of other predicates between those two lines (hawk/1, fish/1, mammal/1, animal/1), hence the definition of bird/1 is discontiguous.
The standard, ISO/IEC 13211-1:1995, states on clauses:
7.4.3 Clauses
[...]
All the clauses for a user-defined procedureP
shall be
consecutive read-terms of a single Prolog text unless there
is a directivediscontiguous(UP)
directive indicatingP
in that Prolog text.
So that leaves you with two options:
1) You add the suggested directive to your source file:
:- discontiguous bird/1.
cat(sylvester).
cat(felix).
.
.
.
2) You alter your source file such that the clauses of bird/1 appear in consecutive lines:
cat(sylvester).
cat(felix).
dog(spike).
dog(fido).
primate(george).
primate("king kong").
bird(tweety).
%then bird if hawk % <- moved here from the end of source file
bird(X) :- hawk(X). % <- moved here from the end of source file
hawk(tony).
fish(nemo).
%then Mammal if cat or dog or primate
mammal(X) :- cat(X) ; dog(X) ; primate(X).
%then Animal if mammal or bird or fish
animal(X) :- mammal(X) ; bird(X) ; fish(X).
Upvotes: 2