Slide 14.16: Simple facts (cont.)
Slide 14.18: Facts with arguments (cont.)
Home

Facts with Arguments


More complicated facts consist of a relation and the items that this refers to. These items are called arguments. Facts can have arbitrary number of arguments from zero upwards. A general model is shown below:
   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.

Examples of Facts with Arguments
The following database details who eats what in some world model:
   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 */