Conjunctions are used to query complex questions.
For example,
You can ask Prolog, ‘tell me the animal that is bigger
than rabbit and smaller than tiger’
You can query these kind of questions using , operator. ,
is pronounced as ‘and’.
For example, the statement ‘bigger(X, rabbit),
bigger(tiger, X).’ return the animal that is bigger than rabbit and smaller
than tiger.
animals.pl
bigger(elephant, fox). bigger(elephant, tiger). bigger(elephant, rabbit). bigger(elephant, ant). bigger(tiger, fox). bigger(tiger, rabbit). bigger(tiger, ant). bigger(fox, rabbit). bigger(fox, ant).
Open Prolog terminal and execute the statement ‘bigger(X,
rabbit), bigger(tiger, X).’
2 ?- bigger(X, rabbit), bigger(tiger, X). X = fox.
You can even combine multiple predicates. For example,
below statement return the animal that is bigger than ant, rabbit and tiger.
3 ?- bigger(X, ant), bigger(X, rabbit), bigger(X, tiger). X = elephant .
No comments:
Post a Comment