Prolog existence_error procedure in basic example
Asked Answered
P

3

8

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.

Polonium answered 4/11, 2017 at 5:34 Comment(3)
looks alright, although your logic of does_come_after is probably a bit flawed. shouldn't cause this error however. How exactly did you call the logic?Zither
Seems that you haven't consult the file which contains the predicates...Addition
I did consult the file, and I tested it using the comes_after() predicate. I updated the post, check the screenshot for specifics. Thanks!Polonium
A
6

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}
Alex answered 4/11, 2017 at 14:54 Comment(2)
Yeah, I think you're right about the version thing. Looks like others have had the same problem as well: lists.gnu.org/archive/html/users-prolog/2017-02/threads.html I downgraded to 1.4.4 and that seems to have resolved the issues!Polonium
@Zoro : UpdatedAlex
H
6

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.

Hinz answered 22/10, 2018 at 7:58 Comment(0)
V
0

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:

  1. By command line: $ gprolog --consult-file my-fancy-definitions, or
  2. From the running interpreter: [my-fancy-definitions].
Vail answered 21/10, 2023 at 23:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.