flowery(X) <- rainy(x) rainy(Portland) ------------ flowery(Portland)
Dense terminology, based on its logical roots. Terms can be of any of these types
A "predicate" is a functor and its arity.
The Horn clauses are either "facts" or "rules". "Facts" have no explicit righthand side (implicitly, they are "fact :- true."), and "rules" do (e.g., "rule :- something.")
So how does this all work? You have to give a goal to be reached; the Prolog engine tries to use the declarations that you have made to deduce that goal (actually, it does the opposite: it tries to prove the negative of the goal false).
Supports "is" arithmetic (but try just "X." with SWI-Prolog).
?- [user]. rainy(seattle). |: rainy(rochester). |: cold(rochester). |: snowy(X) :- rainy(X), cold(X). |: % user://1 compiled 0.01 sec, 5 clauses true. ?- snowy(X). X = rochester.
?- [user]. cold(seattle). Warning: user://2:38: Redefined static procedure cold/1 Previously defined at user://1:26 |: cold(rochester). |: % user://2 compiled 0.00 sec, 2 clauses true. ?- snowy(X). X = seattle ; X = rochester. ?-
Supports "cuts", allowing you to commit to a part of the search tree
Cut allows not only efficiency gains by stopping re-reconsideration ad infinitum, but it allows us to create selection:
statement :- condition, !, then. statement :- else.
?- [user]. natural(1). |: natural(N) :- natural(M), N is M+1. |: looping(N) :- natural(I), write(I), nl, I = N, !. |: % user://3 compiled 0.01 sec, 4 clauses true. ?- looping(5). 1 2 3 4 5 true. ?-