Slide 14.17: Facts with arguments
Slide 14.19: Variables and unification
Home

Facts with Arguments (Cont.)


Examples of Facts with Arguments (Cont.)
   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. */
 ?- eats(mike,apples).   /* Does mike eat apples? */

no /* No, according to the database */
?- eats(fred,apples). /* Does fred eat apples? */
no /* No, we don't know. */
Let us consider another database. This time we will use the predicate age to indicate the ages of various individuals.
   age( john, 32 ).             /* John is 32 years old. */
   age( agnes, 41 ).            /* Agnes is 41. */
   age( george, 72 ).           /* George is 72. */
   age( ian, 2 ).               /* Ian is 2. */
   age( thomas, 25 ).           /* Thomas is 25. */
If we now ask some queries we would get the following interaction:
 ?- age( ian, 2 ).  /* Is Ian 2 years old? */

yes /* Yes, the fourth clause */
?- agnes( 41 ). /* Is agnes 41? */
no /* No. In the database we only */
/* know about the relation age, */ /* not about the relation agnes, */ /* so the query fails. */ ?- age(ian,two). /* Is Ian two years old? */
no /* No. two and 2 are not the same. */
/* Therefore don't match. */