true. vs true
false.. However, in some versions of Prolog, including recent versions of SWI-Prolog another possible response can occur:
truewithout a full-stop/period.
likes(jane, pizza)is in your Prolog program as a fact, but can also be inferred using a rule and some other facts.
?- likes(jane, pizza). true
true is a prompt to
allow you to find out if this is so - i.e. that the query can be proven
in more than one way. Type a semicolon if you want
Prolog to go ahead and look for a different proof.
?- likes(jane, pizza). true ; true . ?-Press "return" if you are happy with a single proof.
If you want to suppress this behaviour, you can insert
cuts to prevent the backtracking that is finding
the extra (possible) proofs, or you can, in SWI-Prolog, use this
or alternatively, put the following directive in your Prolog source code:
:- set_prolog_flag(prompt_alternatives_on, groundness).
You may also be able to avoid responses of
true in some
cases by re-ordering relevant clauses in your program.
Here's some example code to demonstrate
happy(fido). happy(rex). happy(Dog) :- is_dog(Dog), walkies(Dog). happy(Dog) :- is_dog(Dog), chase_car(Dog). is_dog(fido). is_dog(rex). walkies(fido). walkies(rex). chase_car(fido).There are three ways to prove
happy: from the fact, and from each of the two rules. So:
?- happy(fido). true ; true ; true. ?- happy(rex). true ; true ; false.
happy(fido) proven using fact happy(fido) proven using "walkies" rule happy(fido) proven using "chase_car" rule happy(rex) proven using fact happy(rex) proven using "walkies" rule happy(rex) not provable using "chase_car" rule