Part III: Programming


This part gives a general introduction to Prolog. Most of what we say is not specific to Prolog+CG, and can be used in any Prolog environment. We will note, however, when something is specific to Prolog+CG.

An example

Just to whet the appetite, here is an example of a Prolog program written in Prolog+CG. Even though most of Part III is about general Prolog, we will make an exception here and include a CG-parts, which are otherwise only a part of Prolog+CG.

// Type-hierarchy
entity > Person, Act, Haste, Utterance, 
         Proposition, Situation, Manner.
Manner > Loud, Quiet, Wisely, Slow, Fast, Sudden.

// Type-instances
Person = Romeo, FriarLawrence.
Act = Insist, Walk, Run, Stumble.

// CG 1:
// Romeo cries to Friar Lawrence: "I stand on
// sudden haste."
         -Agnt->[Person: Romeo],
         -Rcpt->[Person: FriarLawrence],
         -Thme->[Proposition =
                     [Act: Insist]-
                       -Agnt->[Person: I],
                       -Thme->[Situation =

// CG 2:
// Friar Lawrence says to Romeo: "Wisely and slow,
// they stumble that run fast."
         -Agnt->[Person: FriarLawrence],
         -Rcpt->[Person: Romeo],
         -Thme->[Proposition =
                  [Proposition =
                          [Act: Walk]-
                  ]-Reas->[Proposition =
                              [Act: Stumble]-
                                       [Act: Run]-

// Who talks to whom?
Talk(A,R) :- [r:A]<-Agnt-[Utterance]-Rcpt->[s:R].

This example is available in the AAU directory as "Romeo1.plgCG".

The lines beginning with "//" are comments. The example illustrates the following exchange between Romeo and Friar Lawrence:

Romeo: "I stand on sudden haste!" (I.e., I insist that we haste immediately to proceed with our plans, namely to marry me and Juliet.)

Friar Lawrence: "Wisely and slow. They stumble that run fast."

Difficult things

Now let us say something about the following material. Sometimes, the going may seem to be rough. If this is the case, we advise you to slow down and read slowly, making sure you understand each step in the presentation or explanation. If something is unclear at the moment, perhaps there will be examples later which clarify. Once you have seen these examples, if you still do not understand, it is good to go back and read the presentation again.


Next, we look at the basic datatype in Prolog, namely terms.

7.3.8 Reusing predicates
NextLite: 8 Terms

Prev: 7.3.8 Reusing predicates
Up: Table of contents
Next: 8 Terms