0

Just installed SWI-Prolog on my W8 machine and it's throwing an error.

Here's the error:

ERROR: toplevel: Undefined procedure: mark/0 (DWIM could not correct goal)

Let's say my prolog source file contains one fact:

 Prolog source...

 it_is_monday.   //The fact

So I compile the buffer, and get:

.../documents/prolog/prologSource compiled 0.00 sec, 2 clauses

Now when I input

it_is_monday. 

The output as expected is true. However when I input say,

some_other_statement.

I get the error posted above as opposed to false. Can anyone tell me what's going on here?

Solution: Different prolog version.

3 Answers 3

4

There's a standard Prolog flag, unknown, that is set by default in SWI-Prolog and other modern Prolog compilers to error, meaning that an attempt to call an unknown predicate will result in an exception. This flag can be set (using the standard set_prolog_flag/2 predicate) instead to fail to get the behavior that you seem to be expecting but that's not advisable as it may make debugging harder. E.g. a simply typo in a predicate name will result in a failure which, in a complex program, could be difficult to trace down while a predicate existence error would pinpoint the culprit at the spot.

1
  • Yes, it's a helpful feature. My failure to define a predicate, or some typo/change to naming a predicate, is far and away my most typical error in writing Prolog. Of course if one wants to stub out a predicate with a fail consequence, that can be a useful tactic.
    – hardmath
    Nov 18, 2013 at 19:55
2

You get the error

ERROR: toplevel: Undefined procedure: mark/0 (DWIM could not correct goal)

because you haven't defined the procedure you tried to execute. (that's why it says undefined)

If you define it, by editing your .pl file and writing some_other_statement.

and you run it again, you'll get

1 ?- some_other_statement.
true.

In Prolog you need to define every procedure you want to execute.

When you try to execute an undefined procedure, the name of the procedure will show up in the error. So, if you haven't defined some_other_statement., the error will be:

2 ?-  some_other_statement.
ERROR: toplevel: Undefined procedure: some_other_statement/0 (DWIM could not correct goal)

notice that some_other_statement/0 is being shown on the error that I got.

EDIT : If you wanted to get a false message, you would have to define something like some_other_statement(1). and then execute a query like some_other_statement(12).

2 ?- some_other_statement(12).
false.
2
  • Sorry I didn't state in the question that I was expecting false rather than the error, hence the confusion. I was using an older version of prolog on my other machine which output false when an undefined procedure was presented. Nov 18, 2013 at 18:13
  • I edited my post. I don't know about older versions, but on the current one, you get the mentioned error Nov 18, 2013 at 18:16
-1

if you want to receive false from that you can add the directive

:- dynamic(some_other_statement/0).

at the beggining of the file, so when you execute the query

?- some_other_statement.

you will get false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.