This one tickled my interest in theory:
Is it possible to write an inconsistent Prolog program, i.e. a program that answers both false and true depending on how it is queried, using only pure Prolog, the cut, and false
?
For example, one could query p(1)
and the Prolog Processor would says false
. But when one queries p(X)
the Prolog Processor would give the set of answers 1
, 2
, 3
.
This can be easily achieved with "computational state examination predicates" like var/1
(really better called fresh/1
) + el cut:
p(X) :- nonvar(X),!,member(X,[2,3]).
p(X) :- member(X,[1,2,3]).
Then
?- p(1).
false.
?- p(X).
X = 1 ;
X = 2 ;
X = 3.
"Ouch time" ensues if this is high-assurance software. Naturally, any imperative program has no problem going off the rails like this on every other line.
So. can be done without those "computational state examination predicates"?
P.S.
The above illustrates that all the predicates of Prolog are really carrying a threaded hidden argument of the "computational state":
p(X,StateIn,StateOut).
which can be used to explain the behavour of var/1
and friends. The Prolog program is then "pure" when it only calls predicates that neither consult not modify that State
. Well, at least that seems to be a good way to look at what is going on. I think.