Class Variable

java.lang.Object
  extended byVariable
All Implemented Interfaces:
Unifiable

public class Variable
extends java.lang.Object
implements Unifiable

Variables can be constrained with a list of possible values. Different Variables can have the same name (a Symbol).


Field Summary
(package private)  Symbol name
          The name of this Variable.
(package private)  VariableValueSet values
          The possible values of this Variable (if any, otherwise unconstrained).
 
Constructor Summary
Variable(Symbol name)
          Create an unconstrained Variable with given name.
Variable(Symbol name, VariableValueSet values)
          Create a new Variable with then given name and value restriction.
 
Method Summary
 Unifiable copyWithBindings(BindingSet bindings)
          Returns a new Variable which is a copy of this one with the given bindings applied.
 java.util.Set getValues()
          Returns the Set of possible values for this Variable.
(package private)  boolean occursIn(Expression expr)
          Returns true if this Variable occurs in the given Expression.
 java.lang.String toString()
          Returns the printable representation of this Variable as a String.
 boolean unifyWith(Unifiable other, BindingSet bindings)
          Try to unify this Variable with another Unifiable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

Symbol name
The name of this Variable.


values

VariableValueSet values
The possible values of this Variable (if any, otherwise unconstrained).

Constructor Detail

Variable

public Variable(Symbol name)
Create an unconstrained Variable with given name.


Variable

public Variable(Symbol name,
                VariableValueSet values)
Create a new Variable with then given name and value restriction.

Method Detail

getValues

public java.util.Set getValues()
Returns the Set of possible values for this Variable.


toString

public java.lang.String toString()
Returns the printable representation of this Variable as a String. Variables print with a leading question mark, followed by their name, then their list of constrained values, if any.


unifyWith

public boolean unifyWith(Unifiable other,
                         BindingSet bindings)
Try to unify this Variable with another Unifiable. A Variable unifies as follows:

Specified by:
unifyWith in interface Unifiable

occursIn

boolean occursIn(Expression expr)
Returns true if this Variable occurs in the given Expression.


copyWithBindings

public Unifiable copyWithBindings(BindingSet bindings)
Returns a new Variable which is a copy of this one with the given bindings applied. That is, if this Variable has a binding in bindings, then we return a copy of that, otherwise we return a copy of the Variable with the same name.

Specified by:
copyWithBindings in interface Unifiable