Reputation: 87
I'm making a question and answer system in prolog. If I say, "the color of the car is blue," fact(car, color, blue) is added to the database and prolog returns "OK".
How do I check that this specific fact exists? I know you can check if predicates exists, but I want to know how to check that exactly fact(car, color, blue) exists and not that another fact like fact(car, feeling, smooth) exists.
I'm doing this so that when I say, "the color of the car is blue" it returns, "I know," instead of "OK," since the fact is now in the database.
Upvotes: 2
Views: 3042
Reputation: 3265
The best way to check if a fact exists is to query it.
fact(car, color, blue).
true.
You can use the answer to generate some output to the user:
check(Fact) :-
call(Fact), !,
write('Exists');
write('Doesen\'t exists'), fail.
Consider that Prolog systems make the assumption of closed world. Anything that is not contained in the inner DB is automatically false. Hence, everything that is false, is automatically not contained.
You will have kinda logical isomorphism between what is known/unknown and what is true/false.
Upvotes: 3