Interpreting the error messages and warnings that Prolog may give you
Prolog will tell you if the things that you are writing are
Download the knowledge base kb.syntax_error.pl and load it into Prolog. You will get the following answer.
?- consult('kb.syntax_error.pl'). ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:5: Syntax error: Operator expected ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:11: Syntax error: Operator expected ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:14: Syntax error: Unexpected end of clause ERROR: /home/kris/lehre/esslli04/esslli04prolog/kbs/kb.syntax_error.pl:17: Syntax error: Unexpected end of file % kb.syntax_error.pl compiled 0.00 sec, 1,348 bytes YesThis tells you that there are four syntax errors. It also tells you that the Prolog interpreter thinks that the errors are in lines 6, 12, 15, and 18. And it gives you some indications as to what might cause the problems (operator expected, unexpected end of clause/file).
Which are the mistakes?
Another thing that you might get complaints about are
singleton variables; i.e., variables which are used only once
in a clause. Download the knowledge base kb.singleton_vars.pl and
load it into Prolog. You will get the following:
?- consult('kb.singleton_vars.pl'). Warning: (/home/kris/lehre/esslli04/esslli04prolog/kbs/kb.singleton_vars.pl:8): Singleton variables: [X, Y] % kb.singleton_vars.pl compiled 0.00 sec, 1,520 bytes YesProlog tells you that
Yare singleton variables in the clause starting at line 8. Prolog warns you when it detects singleton variables, because singleton variables are often due to a typo (as in our example). Sometimes you do want to use variables which are mentioned only once in a clause. To avoid getting the singleton variable warning, you should use the anonymous variable
_instead of a named variable in this case.
Finally, Prolog complains when different clause belonging to the
definition of the same predicate are not together in the
file. Here is an example: kb.clauses_not_together.pl. When you load this
knowledge base Prolog answers:
?- consult('kb.clauses_not_together.pl'). Warning: (/home/kris/lehre/esslli04/esslli04prolog/kbs/kb.clauses_not_together.pl:14): Clauses of hate/2 are not together in the source-file % kb.clauses_not_together.pl compiled 0.00 sec, 0 bytes YesThe first clause of the definition of the predicate
hate/2is separated from the other two clauses by a rule with the head