next up previous contents
Next: Compound Terms Up: Prolog Syntax Previous: Constants

Variables

  Variables usually start with a capital letter. The only interesting exception is the special anonymous variable written _ and pronounced ``underscore''. In the rule


process(X
Y):-

generate(_ Z)

test(_ Z)

evaluate(Z Y).

the underscores refer to different unnamed variables. For example here are two versions of member/2.


member(X
[XY]).

member(X [YZ]):-

member(X Z).

member(X [X_]).

member(X [_Z]):-

member(X Z).

Note that in the clause



know_both_parents(X):-

mother(_ X)

father(_ X).

the underscores do not refer to the same object. The reading is roughly that ``we know both the parents of X if someone(name unimportant) is the mother of X and someone else (unimportant) is the father''. Note that Prolog regards the two occurrences of the anonymous variable in the above as different variables.

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