Rules (Cont.)


Rule V
All identically-named variables within a particular rule (e.g. all occurrences of, say, X in the first fun rule below) are constrained to have one and the same instantiation for each solution to a particular query. Identical variable names in separate rules are totally independent, just as if different variable names had been used. To give an example: The program
     fun( X ) :- red( X ),  car( X ).
     fun( X ) :- blue( X ), bike( X ).
is the same as the program
     fun( X_1 ) :- red( X_1 ),  car( X_1 ).
     fun( X_2 ) :- blue( X_2 ), bike( X_2 ).
Thus variable name scoping is per-individual rule (often called a clause). The same variable name may appear in different clauses of a rule, or rules with different names. Each time it is treated as something specific to its context. A variable X may occur in the program many times with many different bindings. It will only have the same bindings when you tell it to.

Examples of Rule I
Consider the following program:
     fun( X ) :- red( X ),  car( X ).
     fun( X ) :- blue( X ), bike( X ).
     car( vw_beatle ).
     car( ford_escort ).
     bike( harley_davidson ).
     red( vw_beatle ).
     red( ford_escort ).
     blue( harley_davidson ).
Above is both our previous program for finding fun items and facts describing some red and blue items and some cars and bikes.