next up previous contents
Next: Rules and Conjunctions Up: Knowledge Representation Previous: Semantics

The Logical Variable

  In the DEC-10 Prolog family, if an object is referred to by a name starting with a capital letter then the object has the status of a logical variable. In the above rule there are two references to X. All this means is that the two references are to the same object ---whatever that object is.

The scope rule for Prolog is that two uses of an identical name for a logical variable only refer to the same object if the uses are within a single clause. Therefore in

 
happy(X):-

healthy(X).

wise(X):-

old(X).

the two references to X in the first clause do not refer to the same object as the references to X in the second clause. By the way, this example is a sort that is discussed in section 2.11.

Do not assume that the word logical is redundant. It is used to distinguish between the nature of the variable as used in predicate calculus and the variable used in imperative languages like BASIC, FORTRAN, ALGOL and so on. In those languages, a variable name indicates a storage location which may `contain' different values at different moments in the execution of the program.

Although this needs some further comments, it is probably better to start with this statement and qualify it later.

For example, in Pascal:
X:= 1; X:= 2;
results in the assignment of 2 to X. In Prolog, once a logical variable has a value, then it cannot be assigned a different one. The logical statement
X=1 X=2
cannot be true as X cannot be both `2' and `1' simultaneously. An attempt to make a logical variable take a new value will fail.


next up previous contents
Next: Rules and Conjunctions Up: Knowledge Representation Previous: Semantics



Paul Brna
Mon May 24 20:14:48 BST 1999