Undefined procedure error in prolog SWI

1.5k views Asked by At

Running prolog SWI on windows 8 for the first time.

this is my program (.pl) file, very basic just with 3 facts: (I'm a complete prolog beginner)

hello.
a.
b.

When I load it (consult) in prolog-SWI, and work with the program, I get this error in my output:

12 ?- b.
true.

13 ?- a.
true.

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

Now if that is a simple error because c was never stated in the program as a fact then that is fine, but after looking at the examples online and the ones I had found in class Prolog in these examples replies yes when a fact is in the program, and no when it is not. Mine replies true if it is, and gives me that long error if it is not.

See this link for example

Where is replies no for foggy.

1

There are 1 answers

0
false On BEST ANSWER

SWI has a slightly different top level shell much inspired by Prolog IV's shell. The idea is that you get back as an answer again an executable query. Therefore true. instead of yes and false. instead of no. This is particularly useful if you want to "paste back" an answer into the next query.

?- append(Xs,Ys,[1,4,7]).
   Xs = [], Ys = [1,4,7]
;  Xs = [1], Ys = [4,7]
;  Xs = [1,4], Ys = [7]
;  Xs = [1,4,7], Ys = []
;  false.

It is even more useful, when you are working with constraints like library(clpfd):

?- use_module(library(clpfd)).
   true.
?- X #> 3, X#>=Y,abs(X) #< 100.
   X in 4..99, X#>=Y, Y in inf..99.

The other problem is common default behavior in many systems: If there is no clause and no other mentioning of a particular predicate, the system assumes that you mistyped the name and gives you an error accordingly. If you really insist (don't!), you can switch behavior time traveling into the late 1970s with set_prolog_flag(unknown, fail). but better switch it back immediately with set_prolog_flag(unknown, error).