I started to learn Prolog following the book Programming in Prolog: Using the ISO Standard. At page 7 of the intro to the language they made the assertion : "In Prolog the answer no is used to mean nothing unifies with the question. It is important to remember that no is not the same as false". So why SWI-Prolog
uses the false
and true
statement instead of yes
or no
?
To begin with, the ISO standard (ISO/IEC 13211-1:1995) does not define a toplevel loop. In 1 Scope it reads:
NOTE — This part of ISO/IEC 13211 does not specify:
...
f) the user environment (top level loop, debugger, library
system, editor, compiler etc.) of a Prolog processor.
Traditionally, the answer of a query has been answered with yes or no. In case of yes, answer substitutions were shown, if present.
Today, with more and more constraints present in answers, the traditional toplevel loop becomes a bit cumbersome to use. What is the correct answer to
?- dif(X,a).
? It cannot be a yes, it might be a maybe,which was used first by Jaffar et al.s CLP(R). But very frequently one wants to reuse the answer.
?- dif(X,a).
dif(X,a).
?- dif(b,a).
true.
?- true.
true.
Following Prolog IV's pioneering toplevel, the idea in SWI is to produce text as an answer such that you can paste it back to get the very same result. In this manner the syntax of answers is specified to some degree - it has to be valid Prolog text.
So if there is no longer yes, why should there be no? For this reason SWI gives false.
as an answer. Prior to SWI, Prolog IV did respond false
. Note for example the following fixpoint in SWI:
?- true ; false.
true
; false.
So even this tiny detail is retained in answers. Whereas in Prolog IV this is collapsed into true
because Prolog IV shows all answers in one fell swoop.
?- true ; false.
true.
For more on answers, see this.
human(socrates).
human(aristotle).
and athenian(socrates).
I would expect a yes
and no
answer instead of a true-flase
to the question ?- athenian(socrates).
and ?-athenian(aristotle).
–
Perfusion true
? or false
? Many humans answer like this too: Socrates is human? True! Prolog is human? False! Or 3 > 2
? true
! –
Degreeday true/0
and false/0
are built-in predicates. By showing you true/0
Prolog says: The answer to your query is exactly the same as the answer to true
/false
. What C&M wants to stress is that the facts in a program are an incomplete description of reality. –
Degreeday I came across this question recently and took a look at an old (third) edition of Clocksin and Mellish which discusses the difference between yes
, no
and true
, false
. From my reading of the text this is what I understand:
yes
andno
are returned after Edinburgh Prolog evaluates a query using its 'database' of facts and rules.yes
means the result is provable from the facts and rules in the database;no
means it's not provable from those rules and facts.true
andfalse
refer to the real world. It's possible for Prolog to returnno
to the queryisAmerican(obama)
simply because this fact is not in the database; whereas in fact (in the real world) Obama is an American and so this fact istrue
in reality.
Edinburgh Prolog returns yes
and no
to queries, however later implementations, like SWI Prolog, return true
and false
. Clearly later implementors didn't consider this distinction very important, but in fact it is a crucial distinction. When Edinburgh Prolog returns a no
then it means "not provable from the database"; and when SWI Prolog returns false
it also means "not provable from the database". They mean the same thing (semantically) but they look different (syntactically) because SWI Prolog doesn't conform entirely to Edinburgh Prolog conventions.
© 2022 - 2024 — McMap. All rights reserved.