head :- body.
head - functor and args, just like a fact.
:- the 'neck' symbol, often read as 'if'
body - one or more goals, just like a query.
This query finds connecting flights between FROM and TO:
?- flight(FROM, VIA, _, FL1, _), flight(VIA, TO, _, FL2, _), not FROM = TO.
If this rule was in the logicbase:
connection(FROM, TO, VIA, FL1, FL2) :- flight(FROM, VIA, _, FL1, _), flight(VIA, TO, _, FL2, _), not FROM = TO.
Then this query would do the same thing:
?- connection(FROM, TO, VIA, FL1, FL2).