Slide 14.16: Simple facts (cont.) Slide 14.18: Facts with arguments (cont.) Home |
relation( <argument1>, <argument2>, …, <argumentN> ).
Relation names must begin with a lowercase letter
likes( john, mary ).
The above fact says that a relationship likes
links john
and mary
.
This fact may be read as either john
likes mary
or mary
likes john
.
This reversibility can be very useful to the programmer, however it can also lead to some pitfalls.
Thus you should always be clear and consistent how you intend to interpret the relation and when.
Finally, remember names of the relations are defined by you.
With the exception of a few relations that the system has built into it, the system only knows about relations that you tell it about.
eats(fred,oranges). /* Fred eats oranges. */ eats(fred,t_bone_steaks). /* Fred eats T-bone steaks. */ eats(tony,apples). /* Tony eats apples. */ eats(john,apples). /* John eats apples. */ eats(john,grapefruit). /* John eats grapefruit. */If we now ask some queries we would get the following interaction:
?- eats( fred, oranges ). /* Does this match anything? */
yes /* Yes, the first clause */ ?- eats( john, apples ). /* Is there a fact saying */ /* john eats apples? */ yes /* Yes, the clause 4 */