Your Prolog fact database needs true/false assertions about the predicates you'd like to query about. A fact database like:
sunny.
rainy.
is actually interpreted as the following predicates:
sunny :- true.
rainy :- true.
These predicates (sunny/0
and rainy/0
) could have had false
instead of true
as the clause body.
A query like:
?- not_sunny.
will only work if there is a predicate not_sunny/0
in the database already. Otherwise, such a query will generate the error you've shown, as not_sunny/0
is an 'undefined procedure'. Instead, you could have asked:
?- \+ sunny.
This uses the negation operator (\+
) in front of a known predicate, sunny/0
. With the database above, given ?- sunny.
is true
, this query will evaluate to false
as you might otherwise have been expecting from ?- not_sunny
.
For more information on Prolog basics, I can highly recommend the site Learn Prolog Now (http://www.learnprolognow.org/).