4.1.2 Variables


Prolog+CG also allows variables to function as relations.

Variables are names we give to values. The cool thing about variables is that their value can change. This makes variables really useful.


Entity > Animal, Act.
Animal = Wolf, Lamb.
Act = Persuade, Eat.

Act([Animal : Wolf]<-AGNT-[Act : Persuade]-RCPT->[Animal : Lamb]).
Act([Animal : Wolf]<-AGNT-[Act : Eat]-PTNT->[Animal : Lamb]).

WolfDoesToLamb(A,R) :- 
          Act([Animal : Wolf]<-AGNT-[Act : A]-R->[Animal : Lamb]).

This program is available in the AAU directory as Aesop1.plgCG.


First, we have the usual type-hierarchy and catalog of instances.

Then we have two facts called "Act" which specify two CGs.

Lastly, we have a rule called "WolfDoesToLamb". It "calls" the "Act" facts with a special CG as the actual parameter.

The CG has two variables, called "A" and "R". The "R" variable is in the place of a relation, whereas the "A" parameter is in the place of a referent.

When calling the "Act" facts, these two variables are "bound" to the corresponding values in the CGs in the "Act" facts.


If we run the following query:

?- WolfDoesToLamb(A,R).

the answer is:

{A = Persuade, R = RCPT}
{A = Eat, R = PTNT}

As we see, the variables have been bound to the correct referents and relations in each CG.


Next, we have a summary.

PrevLite: 4.1.1 Further rules
NextLite: 4.1.3 Summary

Prev: 4.1.1 Further rules
Up: 4.1 Relations
Next: 4.1.3 Summary