Unification and instantiation

Unification and instantiation can be performed explicitly with the '=' operator, or implicitly via parameter transmission. Unification is a symmetric operation (X=Y is the same as Y=X), and is not the same as assignment.

  1. Any value can be unified with itself. (This is normally useful only as a test.)

    Example: mother(john) = mother(john).

  2. A variable can be unified with another variable. The two variable names thereafter reference the same variable.

    Example: X = Y, X = 2, write(Y). /* Writes the value 2. */

  3. A variable can be unified with any Prolog value; this is called instantiating the variable. A variable is fully instantiated if it is unified with a value that does not itself contain variables.

    Example: X = foo(bar, [1, 2, 3]). /* X is fully instantiated. */
    Example: Pa = husband(Ma). /* Pa is partially instantiated. */

  4. Two different values can be unified if there are unifications for the constituent variables which make the values the same.

    Example: mother(mary, X) = mother(Y, father(Z)).
    [Also results in the unifications mary=Y and X=father(Z)].

  5. It is legal to unify a variable with an expression containing itself; however, the resultant value cannot be printed, and must otherwise be handled with extreme care.

    Example: X = foo(X, Y).

Previous page
Table of contents
Next page

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