Variables

A variable is written as a sequence of letters and digits, beginning with a capital letter. The underscore (_) is considered to be a capital letter. Examples: X2, Max, This_node, ThisNode.

Prolog variables are similar to ``unknowns'' in algebra: Prolog tries to find values for the variables such that the entire clause can succeed. Once a value has been chosen for a variable, it cannot be altered by subsequent code; however, if the remainder of the clause cannot be satisfied, Prolog may backtrack and try another value for that variable.

The anonymous variable consists of a single underscore. Each occurrence of the anonymous variable is considered to be a new, distinct variable (i.e. different occurrences may have different values).

The scope of a variable name is the clause in which it occurs. There are no ``global'' variables.

Previous page
Table of contents
Next page


Copyright © 1995 by David Matuszek
All rights reserved.
Last updated July 15, 1995