Reputation: 111
I'm trying to learn the basics of Prolog and keep running into a existence_error with the following code.
comes_after(m1, m2).
comes_after(m2, m3).
comes_after(m3, m4).
comes_after(m4, m5).
comes_after(m5, m6).
does_come_after(X, Y) :- comes_after(X, Y).
does_come_after(X, Z) :- comes_after(X, Y), does_come_after(Y, Z).
When executing a query such as does_come_after(m1, m3) I keep getting the following error.
uncaught exception: error(existence_error(procedure,comes_after/0),does_come_after/0)
Here's a screenshot showing the error:
What am I doing wrong, and what should I keep in mind to avoid these errors in the future? Thanks in advance.
Upvotes: 8
Views: 10422
Reputation: 4293
Assuming you're using GNU prolog, and following Illham's advice, you should create a file (i.e my-fancy-definitions.pl
) and then load it by either:
$ gprolog --consult-file my-fancy-definitions
, or[my-fancy-definitions].
Upvotes: 0
Reputation: 61
Unfortunately, this is a problem with version 1.4.5.
Instead of downgrading, fortunately, there is a trick that you can do:
Instead of using consult(file_name) inside gprolog, you can run this command on your terminal (outside gprolog)
gplc file_name.pl
it will output an executable that you can run by
./file_name
it should solve your existence error problem.
Upvotes: 6
Reputation: 10102
The error message tells you that Prolog expects a predicate comes_after/0
, but none is found. Further, this problem arises when being called from a predicate does_come_after/0
. Now, your definitions all use arity 2. Thus comes_after/2
and does_come_after/2
. So what the system expects cannot happen.
And if it does, this must be related to your installation. You have 1.4.5 which is the most recent version, 1.4.4 the still current stable.
It is thus possible that you have another, older, system installed which interferes by providing an incompatible pl2wam
compiler. To verify this, say which pl2wam
or pl2wam --version
.
In particular, versions from 1.3 or even 1.2 may produce such results. There is no version checking for this in GNU.
To ensure that I get always the right version, I say:
export PATH=/opt/gupu/gprolog-1.4.5/bin:${PATH}
Upvotes: 6