0
votes

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

3 Answers

4
votes

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.

2
votes

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.
-1
votes

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