Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prolog existence_error procedure in basic example

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:

Prolog Error

What am I doing wrong, and what should I keep in mind to avoid these errors in the future? Thanks in advance.

like image 384
Zoroshino Avatar asked Nov 04 '17 05:11

Zoroshino


2 Answers

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}
like image 91
false Avatar answered Nov 15 '22 09:11

false


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.

like image 42
Ilham Firdausi Putra Avatar answered Nov 15 '22 09:11

Ilham Firdausi Putra